Return a new DateTime object and then format the date.
<?php $date=date_create(“2013-03-15”); echo date_format($date,“Y/m/d”); ?> |
The date_create() function returns a new instance of the DateTime object.
date_create(time, timezone) |
Parameter |
Description |
time |
Optional. Specifies a date/time string; NULL indicates the current time. |
timezone |
Optional. Specifies the timezone for the time; defaults to the current timezone. |
Return Value: |
Returns a new DateTime object on success; FALSE or an Exception on failure. |
PHP Version: |
5.2+ |
PHP Changelog: |
In PHP 7.1, microseconds are now populated with their actual value rather than just “00000”. In PHP 5.3, an exception is thrown for invalid time values, whereas previously an error was generated. |
Return a new DateTime object (with the specified timezone) and then format the date and time.
<?php $date=date_create(“2013-03-15 23:40:00”,timezone_open(“Europe/Oslo”)); echo date_format($date,“Y/m/d H:iP”); ?> |