Reputation: 93
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?
Upvotes: 5
Views: 21306
Reputation: 412
you may try this for insert
INSERT into Table_name (colunm_name) VALUES ('".time()."');
Upvotes: 0
Reputation: 433
if u want to insert timestamp i.e. some integer value into mysql field; the field type should be "timestamp" not "datetime" then I hope your integer value will be accepted by the DB
Upvotes: 0
Reputation: 2020
Try using something like "INSERT INTO entries (date) VALUES ('".time()."')"
Upvotes: 1
Reputation: 38298
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
Upvotes: 18