php / mysql date not updating..

Discussion in 'PHP' started by afridy, Jun 30, 2011.

  1. #1
    Hai folks,

    Mysql :
    field name : dt
    Data type : datetime

    php :

    $dt=date('Y-m-d h:i:sa');
    Code (markup):
    above code correctly prints 2011-06-30 08:27:23pm

    Problem is the Ante meridiem is not added to the date in mysql.
    it just shows for example : 2011-06-30 08:27:23

    Why Ante meridiem is not saving :confused:
     
    Last edited: Jun 30, 2011
    afridy, Jun 30, 2011 IP
  2. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #2
    I just convert it to unixtime then store it to a int value in mysql. Then when I need to show it use the date function to convert the saved unixtime to the date.
     
    exodus, Jul 1, 2011 IP
  3. afridy

    afridy Well-Known Member

    Messages:
    810
    Likes Received:
    116
    Best Answers:
    0
    Trophy Points:
    135
    #3
    Hai exodus,
    if i store the date time as unixtime, will ORDER BY dt works? coz i use to order result sets by dt field only.
     
    afridy, Jul 1, 2011 IP
  4. afridy

    afridy Well-Known Member

    Messages:
    810
    Likes Received:
    116
    Best Answers:
    0
    Trophy Points:
    135
    #4
    Thanks exodus, sorting also work with your solution :)
     
    afridy, Jul 1, 2011 IP
  5. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #5
    saves space in the mysql query too. :) I am glad it worked for you. it works for me.
     
    exodus, Jul 1, 2011 IP