insert current timestamp into mysql with php?
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()."')"
Admin
Updated on December 01, 2020Comments
-
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())
. TheNOW
thing will store a formatted date, like2012-04-12 23:09:54
. I don't want that. I want to store the integer value. how do I do that? -
leepowers about 12 yearsAlso the
NOW()
is redundant as without an argumentUNIX_TIMESTAMP()
will use the current time.