将 mysql DATETIME 列转换为纪元秒

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10839151/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:35:47  来源:igfitidea点击:

Convert mysql DATETIME column to epoch seconds

mysqlsqldatetimeepoch

提问by David542

I have a column mysql datetimethat is in DATETIME format.

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

Is there a way to SELECTthis 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?

有没有办法SELECT在纪元秒内访问此列?如果没有,将日期时间格式转换为纪元秒的最佳方法是什么?哪种类型的字段最适合捕获此内容?

回答by John Conde

Use MySQL's UNIX_TIMESTAMPfunction

使用 MySQL 的UNIX_TIMESTAMP功能

回答by Akarun

You can use :

您可以使用 :

SELECT UNIX_TIMESTAMP(yourfield) FROM yourtable;

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

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