Function of the day: MySQL’s FROM_UNIXTIME()

Some PHP applications (EG Drupal) store timestamps as Int(11) fields in MySQL.

To format these as a MySQL date, use FROM_UNIXTIME:

FROM_UNIXTIME(my_field).

Once you’ve got that far, you can format the date how you like with DATE_FORMAT:

DATE_FORMAT(FROM_UNIXTIME(last_login), '%d/%m/%Y %H:%i:%s')


Leave a comment