Thursday, December 15, 2011

MySQL - Convert MySQL date, datetime, timestamp to unix time and Vice versa

To convert Unix time to regular MySQL DATETIME
select from_unixtime('1213907115');
It prints '2008-06-19 16:25:15'

To Convert DATETIME to unixtime
select unix_timestamp('2008-06-19 16:25:15');
It prints 1213907115

To Convert current date & time to unix time.
select unix_timestamp();

To Convert a column of DATETIME type to unixtime.
select unix_timestamp(c8013_date_created) from RealTimeStatus.T8013_PROGRAM;

No comments :

// Below script tag for SyntaxHighLighter