Scott
Scott

Reputation: 6251

Converting date from the column to the unix_timestamp

I got date, stored in MySQL column like this: 09-11-2012 (format is DD/MM/YYYY), but when I do:

SELECT UNIX_TIMESTAMP(t.date) FROM table t;

It does returns 0 for every single row.

How can I convert this format date to the unix timestamp? I would like to convert this date just like the PHP's strtotime is doing it.

Upvotes: 0

Views: 330

Answers (1)

John Woo
John Woo

Reputation: 263733

I guest t.date is a string right? try converting it to DATE first using STR_TO_DATE

SELECT UNIX_TIMESTAMP(STR_TO_DATE(t.date, '%d-%m-%Y')) 
FROM table t;

Upvotes: 3

Related Questions