abipc
abipc

Reputation: 1035

MySQL - Convert "hh:mm PM" to unix timestamp

Given - Due to some bad design (legacy), one of the columns in my table(named delivery_time) has 'delivery time' stored as string in the format 'hh:mm PM'. I have another column (named delivery_date) with 'date' data type with format yyyy-mm-dd.

What to do - Using the information in these two columns I need to find date (day and time) in unix timestamp..

I was able to convert delivery_date to unix timestamp using the following function -

unix_timestamp(cast(delivery_date as date))

Can anyone suggest how to take care of delivery_time column?

Upvotes: 0

Views: 169

Answers (1)

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38552

Not verified but i guess this will work for you

SELECT   
UNIX_TIMESTAMP(CONCAT(delivery_date, ' ', 
STR_TO_DATE(delivery_time,'%h:%i %p)) AS  
my_unix_timestamp

Upvotes: 1

Related Questions