SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Stamford, CT, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile Formatting datestamp in printf()

    Hi,

    Can't find this in the php docs.

    How do you format a MySQL timestamp variable in printf?

    For example, I want to display yyyy-mm-dd hh:mm

    Thanks, Ed

  2. #2
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think there's any allowance for that, I'd just use %s.
    TuitionFree — a free library for the self-taught
    Anode Says...Blogging For Your Pleasure

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Stamford, CT, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by Ed Hunter
    Hi,

    Can't find this in the php docs.

    How do you format a MySQL timestamp variable in printf?

    For example, I want to display yyyy-mm-dd hh:mm

    Thanks, Ed
    Figured it out! It's not pretty but here it is:

    Code:
    printf("%s/%s/%s  %s:%s:%s",
       substr($datetime,0,4), substr($datetime,4,2), 
       substr($datetime,6,2), substr($datetime,8,2), 
       substr($datetime,10,2), substr($datetime,12,2));
    Ed

  4. #4
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just use date() for that?
    TuitionFree — a free library for the self-taught
    Anode Says...Blogging For Your Pleasure

  5. #5
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can also format the date with the mysql function Date_format() [ http://www.mysql.com/doc/en/Date_and...functions.html ]

    It works similar to the php's date function.

  6. #6
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Stamford, CT, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    Quote Originally Posted by anode
    Why not just use date() for that?
    YES! That's what I was looking for.

    I'm new to PHP and don't what functions I have available.

    Thanks, Ed

  7. #7
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Stamford, CT, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Chris82
    You can also format the date with the mysql function Date_format() [ http://www.mysql.com/doc/en/Date_and...functions.html ]

    It works similar to the php's date function.

    Thanks, that would be very handy.

    I have a lot to learn ;>)

    But do the date functions work with datetime and timestamp fields? It's not clear from the page you referred me to.


    Thanks, Ed


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •