将MySQL日期时间24小时格式转换为UNIX时间戳



我将日期时间以这种格式存储在04-09-2019 10:31:AM(2019年9月4日上午10:31(的MySQL表中。

我可以知道如何在sql查询中将此格式转换为unixtime戳吗

首先,您需要使用str_to_date()函数将其转换为适当的mysql日期时间。

str_to_date(dd, '%d-%m-%Y %h:%i:%p')

然后,在获得正确的datetime值后,使用unix_timestamp()函数将其转换为unix时间戳。

select 
unix_timestamp(str_to_date(dd, '%d-%m-%Y %h:%i:%p'))
from test

试试这个dbfiddle。

最新更新