PHP date_create() Function
Definition
The date_create() function returns a new DateTime object.
Syntax
PHP date_create() Function has the following syntax.
date_create(time,timezone);
Parameter
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. |
Return
PHP date_create() Function returns a new DateTime object on success. FALSE on failure.
Example 1
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.
Example 2
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.