将mysql DATETIME列转换为纪元秒

时间:2020-12-31 11:28:34

I have a column mysql datetime that is in DATETIME format.

我有一个以DATETIME格式的列mysql日期时间。

Is there a way to SELECT this column in epoch seconds? If not, what would be the best way of converting the datetime format to epoch seconds? What type of field would be the best to capture this?

有没有办法在epoch秒中选择此列?如果没有,将日期时间格式转换为纪元秒的最佳方法是什么?什么类型的领域最好捕获这个?

2 个解决方案

#1


31  

Use MySQL's UNIX_TIMESTAMP function

使用MySQL的UNIX_TIMESTAMP函数

#2


17  

You can use :

您可以使用 :

SELECT UNIX_TIMESTAMP(yourfield) FROM yourtable;

And for UPDATE, the invers function is : FROM_UNIXTIME(...)

对于UPDATE,invers函数是:FROM_UNIXTIME(...)

#1


31  

Use MySQL's UNIX_TIMESTAMP function

使用MySQL的UNIX_TIMESTAMP函数

#2


17  

You can use :

您可以使用 :

SELECT UNIX_TIMESTAMP(yourfield) FROM yourtable;

And for UPDATE, the invers function is : FROM_UNIXTIME(...)

对于UPDATE,invers函数是:FROM_UNIXTIME(...)