Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert dd/mm/yyyy string to Unix timestamp in MySQL

Tags:

mysql

In my table I have a varchar column called date containing string representations of dates in dd/mm/yyyy format. How can I convert these to Unix times in a SELECT query?

like image 529
Zizo Avatar asked May 30 '11 16:05

Zizo


2 Answers

select unix_timestamp(str_to_date('30/05/2011','%d/%m/%Y'));

or:

select unix_timestamp(str_to_date(myfield,'%d/%m/%Y')) from mytable;
like image 194
ADW Avatar answered Oct 21 '22 23:10

ADW


I think UNIX_TIMESTAMP should do the trick. Can you specify your select query here?

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_unix-timestamp

like image 2
kuriouscoder Avatar answered Oct 22 '22 00:10

kuriouscoder