[英]Convert MySQL date time 24 hour format to UNIX timestamp
I'm storing date time in 04-09-2019 10:31:AM
(4 September 2019 10:31 AM) in this format in MySQL table.我在 MySQL 表中以这种格式存储
04-09-2019 10:31:AM
(2019 年 9 月 4 日上午 10:31)的日期时间。
May I know how to convert this format to unixtime
stamp in sql query我可以知道如何在 sql 查询中将此格式转换为
unixtime
戳
First you need to convert this into a proper mysql datetime using str_to_date()
function.首先,您需要使用
str_to_date()
函数将其转换为正确的mysql日期str_to_date()
。
str_to_date(dd, '%d-%m-%Y %h:%i:%p')
Then after getting the correct datetime value, use unix_timestamp()
function to convert it to unix timestamp.然后在获得正确的日期时间值后,使用
unix_timestamp()
函数将其转换为 unix 时间戳。
select
unix_timestamp(str_to_date(dd, '%d-%m-%Y %h:%i:%p'))
from test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.