The date_create() function returns a new DateTime object.
PHP date_create() Function has the following syntax.
date_create(time,timezone);
PHP date_create() Function has the following parameters.
Parameter | Is Required | Description |
---|---|---|
time | Optional. | A date/time string. NULL indicates the current time. |
timezone | Optional. | Timezone of time. Default is the current timezone. |
PHP date_create() Function returns a new DateTime object on success. FALSE on failure.
Return a new DateTime object, and then format the date:
<?php
$date=date_create("2013-01-15");
echo date_format($date,"Y/m/d");
?>
The code above generates the following result.
Return a new DateTime object (with a given timezone), and then format the date and time:
<?php
$date=date_create("2013-02-15 21:40:00",timezone_open("Europe/Oslo"));
echo date_format($date,"Y/m/d H:iP");
?>
The code above generates the following result.