Sometimes you need to do something with a Timestamp taken from MySQL. Whether that is formatting the Timestamp for better user readability, or to do some sort of processing with it, this can be easily accomplished by converting the Timestamp to a Date. The format of a Timestamp in MySQL is:
We can convert to a Date simply by using PHP's strtotime function:'YYYY-MM-DD HH:MM:SS'
//Normally the Timestamp would come from MySQL, but //for the example I will define it here. $timestamp = '2010-08-08 15:25:18'; echo date('D M j G:i:s Y', strtotime($timestamp)); echo '<br>'; echo date('d-m-y', strtotime($timestamp));
This will output the following lines:
Sun Aug 8 15:25:18 2010
08-08-10
Read more about the date and strtotime functions.
No comments:
Post a Comment