THE WORLD'S LARGEST WEB DEVELOPER SITE

PHP date_create() Function

❮ PHP Date/Time Reference

Example

Return a new DateTime object, and then format the date:

<?php
$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);

Parameter Description
time Optional. Specifies a date/time string. NULL indicates the current time
timezone Optional. Specifies the timezone of time. Default is the current timezone.

Tip: Look at a list of all supported timezones in PHP

Technical Details

Return Value: Returns a new DateTime object on success. FALSE on failure
PHP Version: 5.2+
Changelog: From PHP 5.3+; an exception is thrown if an invalid date is specified

More Examples

Example 1

Return a new DateTime object (with a given 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");
?>
Run example »

❮ PHP Date/Time Reference