PHP date

Discussion in 'Programming' started by dean5000v, Mar 25, 2009.

  1. #1
    hey well ive done a registration form and now i just want to add the registration date into the database ive tried setting the date to date variable like:

    $time = date("Y-m-d");

    and then just put the $time into the sql statment but when i look at the time colum in the database it formats the date like 1981.

    does anyone have any other methods i could use ?
     
    dean5000v, Mar 25, 2009 IP
  2. kuzmanin

    kuzmanin Peon

    Messages:
    242
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    kuzmanin, Mar 25, 2009 IP
  3. crivion

    crivion Notable Member

    Messages:
    1,669
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    210
    Digital Goods:
    3
    #3
    what is the datatype of the column in mysql table? maybe you set it to INT and it needs to be DATE
     
    crivion, Mar 25, 2009 IP
  4. ads2help

    ads2help Peon

    Messages:
    2,142
    Likes Received:
    67
    Best Answers:
    1
    Trophy Points:
    0
    #4
    To save time to mysql DATETIME field, you can either use "NOW()" in the query or $time = date("Y-m-d H:i:s");

    - ads2help
     
    ads2help, Mar 25, 2009 IP
  5. robertstr

    robertstr Member

    Messages:
    218
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #5
    The first parameter in the date() function specifies how to format the date/time. It uses letters to represent date and time formats. Here are some of the letters that can be used:

    d - The day of the month (01-31)
    m - The current month, as a number (01-12)
    Y - The current year in four digits
    An overview of all the letters that can be used in the format parameter, can be found in PHP Date reference
     
    robertstr, Mar 25, 2009 IP
  6. huyhoa

    huyhoa Active Member

    Messages:
    214
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    You should store time in your database in timstam format (Google for timestam)
    And when you want to display it, just call it from database and use your choice
    $t = gmdate('d-m-Y', $time) // Or use what format you like: Y-m-d,...
    PHP:
    Which $time is one you query from database

    Or want to store Y-m-d in your databse, try to Type of your column to varchar
     
    huyhoa, Mar 25, 2009 IP
  7. boompie

    boompie Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Agreed.
    This is called the Epochtime.
    Storing dates this way, allows you to easily make calculations etcetera.

    Rgds,
    Carl
     
    boompie, Mar 25, 2009 IP