insert current timestamp into mysql with php?

21,206

Solution 1

Use MySQL's UNIX_TIMESTAMP() function to get the current epoch time:

INSERT INTO mytable SET tstamp = UNIX_TIMESTAMP();

http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp

Solution 2

Try using something like "INSERT INTO entries (date) VALUES ('".time()."')"

Share:
21,206
Admin
Author by

Admin

Updated on December 01, 2020

Comments

  • Admin
    Admin over 3 years

    This is driving me crazy. I've searched it on interent but can't get to a conclusion.

    I have a date field in my database. Which I'm retrieving values with date function just fine.

    Problem is I did it some time ago, and I don't remember how I inserted those values into that field. it's an integer value (according to what I read, the number of seconds since jan 1st 1970, for example 1338949763. but when I try inserting stuff, like using INSERT INTO entries (date) VALUES (NOW()) . The NOW thing will store a formatted date, like 2012-04-12 23:09:54. I don't want that. I want to store the integer value. how do I do that?

  • leepowers
    leepowers about 12 years
    Also the NOW() is redundant as without an argument UNIX_TIMESTAMP() will use the current time.