Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL - Convert MM/DD/YY to Unix timestamp

Is there an easy (single query) way to do this?

I'm reading those values from a column in a table and I think that the column itself is defined as a string (can't be helped, i'm afraid).

like image 356
João Pereira Avatar asked Aug 05 '10 09:08

João Pereira


2 Answers

Use UNIX_TIMESTAMP;

SELECT UNIX_TIMESTAMP('2007-11-30 10:30:19');

Update:

SELECT UNIX_TIMESTAMP(CAST(fieldName AS DATE));
like image 137
Sarfraz Avatar answered Sep 21 '22 02:09

Sarfraz


SELECT UNIX_TIMESTAMP(STR_TO_DATE('08/05/10','%m/%d/%y'));
like image 35
Wrikken Avatar answered Sep 19 '22 02:09

Wrikken