Covert mysql date time 24 hour format to unix timestamp

Bijesh Samani :

I'm storing date time in "04-09-2019 10:31:AM" in this format in mysql table May i know how to convert this format to unixtime stamp in sql query

Ed Bangga :

First you need to convert this into a proper mysql datetime using str_to_date() function.

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.

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

try this dbfiddle.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=23672&siteId=1