PHP date_create()Functions
PHP Date/Time Reference Manual
Examples
Returns a new DateTime object, then formats the date:
<?php
$date=date_create("2013-03-15");
echo date_format($date,"Y/m/d");
?>
$date=date_create("2013-03-15");
echo date_format($date,"Y/m/d");
?>
Run example »
Definition and Usage
The date_create() function returns a new DateTime object.
Syntax
date_create(time,timezone);
| Parameters | Description |
|---|---|
| time | Optional. Specifies a date/time string. NULL indicates the current date/time. |
| timezone | Optional. Specifiestimethe timezone. Default is the current timezone. Tip: See the list of all timezones supported in PHP |
Technical Details
| Return Value: | Returns a new DateTime object on success, or FALSE on failure. |
|---|---|
| PHP Version: | 5.2+ |
| Changelog: | As of PHP 5.3+, an exception is thrown if an invalid date is specified. |
More Examples
Example 1
Returns a new DateTime object with a given timezone, then formats 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");
?>
$date=date_create("2013-03-15 23:40:00",timezone_open("Europe/Oslo"));
echo date_format($date,"Y/m/d H:iP");
?>
Run example »
PHP Date/Time Reference Manual Other Extensions