Mysql LONGTEXT使用时间戳字符串到实际的TIMESTAMP

时间:2015-11-24 17:39:11

标签: mysql datetime timestamp

我很难接受这个,并且第一次需要一些帮助。

我有一个数据库字段,它是mysql LONGTEXT,带有一个时间戳字符串,例如字符串" 1448386279"

我需要将其转换为正确的MySql TIMESTAMP字段。

所以

insert into temp (timestampfield) VALUES (UNIX_TIMESTAMP('1448377601'));
insert into temp (timestampfield) values(cast('1448377601' as time));
insert into temp (timestampfield) VALUES (UNIX_TIMESTAMP(cast('1448377601' as UNSIGNED)));

所有在时间戳字段中插入null(temp是一个真实的表,而不是临时表,我只是命名它!)。

您可以给予的任何帮助都非常感谢!

此致 BlakeyUK

2 个答案:

答案 0 :(得分:2)

确保timestampfield是日期时间列,然后您可以使用FROM_UNIXTIME函数:

insert into temp (timestampfield) values (from_unixtime('1448377601'))

请看小提琴here

答案 1 :(得分:0)

噢,我是个白痴。 MySQL时间戳不是unix时间戳。我需要的是一个简单的INTEGER字段来存储它。