Quantcast
Channel: Tips and Tricks
Viewing all articles
Browse latest Browse all 16

MySQL Datetime to PHP date format

$
0
0

An easy one today. I often have to remind myself of how to convert a MySQL datetime to something a little more usable... a UNIX timestamp.

The strototime version

It is incredibly easy, just use the PHP strtotime function.

$timestamp=strtotime($result->my_datetime);

Now you can print the date in any format you want:

printdate("Y-m-d H:i:s",$timestamp);

PHP5 Convert MySQL Datetime to PHP date format

If you are using PHP5, the following should accomplish the same thing.

 


Viewing all articles
Browse latest Browse all 16

Trending Articles