logo

:: Date formatting in PHP ::

Question:

How do I convert date from MySQL date format (e.g.: 2009-12-25) to human-readable format in PHP?


Answer:

Here is how to print out various date formats given a date in MySQL format in PHP:

<?php
echo date("m/d/Y", strtotime("2009-12-25"));   // "12/25/2009"
echo date("m-d-Y", strtotime("2009-12-25"));   // "12-25-2009"
echo date("d/m/Y", strtotime("2009-12-25"));   // "25/12/2009"
echo date("d-m-Y", strtotime("2009-12-25"));   // "25-12-2009"
echo date("j F Y", strtotime("2009-12-25"));   // "25 December 2009"
echo date("jS of F Y", strtotime("2009-12-25"));   // "25th of December 2009"
echo date("l, j F Y", strtotime("2009-12-25"));   // "Friday, 25 December 2009"
?>

<< Back to Questions and Answers

© Copyright php-etc.com 2010. Please contact the webmaster for all enquiries.