The date_format() function is a built-in function in PHP programming language. This funtion will return a new DateTime object and then format the date. In this post, I will share a PHP date_format() function with example.
Below is the Syntax of date_format() funtion in PHP code.
1 | date_format(object,format); |
1 2 3 4 | <?php $date=date_create("2013-03-15"); echo date_format($date,"Y/m/d H:i:s"); ?> |
2013/03/15 00:00:00
1 2 3 4 | <?php $date = date_create_from_format('j-M-Y', '15-Feb-2009'); echo date_format($date, 'Y-m-d'); ?> |
2009-02-15
1 2 3 4 | <?php $date = DateTime::createFromFormat('j-M-Y', '15-Feb-2009'); echo $date->format('Y-m-d'); ?> |
2009-02-15
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.