Get Current Time

Discussion in 'PHP' started by Shaimaa, May 26, 2010.

  1. #1
    I want to get the current time of the system in a format like:

    2010-06-11 14:12:09

    Thank you in advance
     
    Shaimaa, May 26, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    date("Y-m-d h:i:s");
     
    bartolay13, May 26, 2010 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
  4. kidatum

    kidatum Peon

    Messages:
    61
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    In the query statement itself instead of the value place this function CURDATE().

    So, like: $dbConnection->query("INSERT INTO table (someDate, x, x, x) VALUES(CURDATE(), y, y, y)"); - I did not test this, but seems to be right, Xs and Ys are just other values.
     
    kidatum, May 26, 2010 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    If you need time in there as well, you would use NOW() instead of CURDATE(). Usually I use NOW for both as the overhead is negligible. If you use CURDATE on a timestamp or datetime column you end up with zero's in the time section of the column.
     
    jestep, May 27, 2010 IP
  6. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #6
    why not use NOW() on mysql?
     
    bartolay13, May 27, 2010 IP
  7. cupi

    cupi Greenhorn

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    Yep, NOW() is good.
     
    cupi, May 27, 2010 IP