Tuesday 30 July 2019

MySQL – Convert Unix Timestamp to Date Time

I think you already know that the Unix Timestamp is not Human readable values it is just set of Integer numbers to the user when you show it on the screen.
Because of this reason we need to convert it before present it to the user.
If you do not convert the value while selecting rows from the Database Table then you are doing this programmatically after SELECT.
In the PHP you can use the date() function for converting.
$timestamp = 1476956996;
echo "date time : ".date('d-M-Y H:i:s a',$timestamp);
This gives the following output –
date time : 20-Oct-2016 11:49:56 am
In simple terms, the Unix timestamp stores the current Date Time in Integer format.
In this short tutorial, I show how you can convert Unix Timestamp value to readable Date Time format when you select data from the MySQL Database Table.

0 comments:

Post a Comment