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.
我的数据库中有一个日期字段。我用date函数来检索值。
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?
问题是我以前做过,我不记得我是怎么把这些值插入那个字段的。它是一个整数值(根据我的阅读,从1970年1月1日开始的秒数,例如1338949763。但是当我尝试插入东西时,比如使用INSERT INTO (date)值(NOW())。现在的东西将存储格式化的日期,比如2012-04-12 23:09:54。我不希望这样。我想要存储整数值。我该怎么做呢?
5 个解决方案
#1
18
Use MySQL's UNIX_TIMESTAMP()
function to get the current epoch time:
使用MySQL的UNIX_TIMESTAMP()函数获得当前纪元时间:
INSERT INTO mytable SET tstamp = UNIX_TIMESTAMP();
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html function_unix-timestamp
#2
1
Try using something like "INSERT INTO entries (date) VALUES ('".time()."')"
尝试使用“插入到条目(日期)值('”.time().")”之类的方法。
#3
0
The correct function is:
正确的函数是:
getdate()
NOT
不
NOW()
#4
0
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
如果你想在mysql字段中插入时间戳,比如某个整数值;字段类型应该是“timestamp”而不是“datetime”,那么我希望DB能够接受您的整数值
#5
0
you may try this for insert
你可以试试这个插入
INSERT into Table_name (colunm_name) VALUES ('".time()."');
#1
18
Use MySQL's UNIX_TIMESTAMP()
function to get the current epoch time:
使用MySQL的UNIX_TIMESTAMP()函数获得当前纪元时间:
INSERT INTO mytable SET tstamp = UNIX_TIMESTAMP();
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_unix-timestamp
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html function_unix-timestamp
#2
1
Try using something like "INSERT INTO entries (date) VALUES ('".time()."')"
尝试使用“插入到条目(日期)值('”.time().")”之类的方法。
#3
0
The correct function is:
正确的函数是:
getdate()
NOT
不
NOW()
#4
0
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
如果你想在mysql字段中插入时间戳,比如某个整数值;字段类型应该是“timestamp”而不是“datetime”,那么我希望DB能够接受您的整数值
#5
0
you may try this for insert
你可以试试这个插入
INSERT into Table_name (colunm_name) VALUES ('".time()."');