date function & variable Question

Discussion in 'PHP' started by bobby9101, Oct 2, 2006.

  1. #1
    hello,
    i have variable $foo that is pulling a date from MySQL that has the date stored in this format: 0000-00-00 00:00:00 (Year-Month-Day Hour:Minute:Second)
    how can I format the date stored in $foo?
     
    bobby9101, Oct 2, 2006 IP
  2. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #2
    I dunno if that will happen without a custom function off hand.

    The date should be stored as a Unix timestamp and then date() used to format it.

    Any way, break it out and use mktime to pull it off. http://us3.php.net/manual/en/function.mktime.php
     
    noppid, Oct 2, 2006 IP
  3. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #3
    how can i use the date and variable at the same time is my question i guess.
     
    bobby9101, Oct 2, 2006 IP
  4. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #4
    noppid, Oct 2, 2006 IP
  5. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i couldn't figure it out?
    have some example code?
     
    bobby9101, Oct 2, 2006 IP
  6. noppid

    noppid gunnin' for the quota

    Messages:
    4,246
    Likes Received:
    232
    Best Answers:
    0
    Trophy Points:
    135
    #6
    noppid, Oct 2, 2006 IP
  7. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Use strtotime() and then date() to format it.
     
    penagate, Oct 3, 2006 IP
  8. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #8
    You can also get the mysql date fields in unix timestamp format with UNIX_TIMESTAMP like this:
    Then format it as you need with date().
     
    wmtips, Oct 3, 2006 IP
  9. ip076

    ip076 Peon

    Messages:
    79
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Here's what you need to do, its pretty simple:

    
    
    $NewDate = date("String format you want", strtotime($foo));
    
    
    PHP:

    or you could do what wmtips mentioned by storing the UNIX timestamp in $foo and then do this:

    
    $NewDate = date("String format you want", $foo);
    
    PHP:

    or you could even just do it all in the query using the MySQL Function DATE_FORMAT
     
    ip076, Oct 3, 2006 IP