PHP date_create() Function

What is PHP date_create() Function?

If you want to perform date/time calculations using DateTime object, consider using PHP date_create() function. The function creates a new DateTime object and it is a procedural representation of the object-oriented DateTime:: __construct() method.

Syntax:

date_create(datetime, timezone)

Parameters:

The Function has 2 parameters that are optional-

datetime (Optional): It specifies a date/time string. If omitted or NULL, the function uses current local date and time.

The datetime string must follow some predefined formats. Supported date and time formats with other detail here- https://www.php.net/manual/en/datetime.formats.php.

timezone (Optional): It specifies a timezone object. If omitted, the function uses current local timezone.

Return Values:

The function returns-

  • A new DateTime object, on success.
  • FALSE, on failure.

Examples:

Example 1:

<?php
// Displaying local current date and time.
$datetimeObj = date_create();
echo "Current date and time is: ". date_format($datetimeObj, "d-m-Y H:i:s");
?>

Output:

Current date and time is: 12-01-2026 11:26:07

Example 2:

<?php
// Displaying date from a specific date.
$datetimeObj = date_create("12-01-2026");
echo "Current date and time is: ". date_format($datetimeObj, "d-m-Y");
?>

Output:

Current date and time is: 12-01-2026

Example 3:

<?php
// Displaying a date & time from a specific timezone.
$datetimeObj_dhaka = date_create('now', new DateTimeZone('Asia/Dhaka'));
$datetimeObj_la    = date_create('now', new DateTimeZone('America/Los_Angeles'));
$datetimeObj_ny    = date_create('now', new DateTimeZone('America/New_York'));

echo "Local Dhaka Time: " . date_format($datetimeObj_dhaka, 'd-m-y H:i:s') . "<br />";
echo "Local LA Time:    " . date_format($datetimeObj_la, 'd-m-y H:i:s') . "<br />";
echo "Local New York Time:    " . date_format($datetimeObj_ny, 'd-m-y H:i:s') . "<br />";
?>

Output:

Local Dhaka Time: 12-01-26 16:26:07
Local LA Time: 12-01-26 02:26:07
Local New York Time: 12-01-26 05:26:07

Example 4:

<?php
// Displaying date using both procedural & object-oriented style.
$datetimeObj = date_create('12-01-26 16:23:20');

echo date_format($datetimeObj, 'd-m-y H:i:s') . "<br />";
echo $datetimeObj->format('d-m-y H:i:s');
?>

Output:

26-01-12 16:23:20
26-01-12 16:23:20

Example 5:

<?php
// Converting atime from one timezone to another.
$datetimeObj = date_create('2026-01-12 16:35:00', new DateTimeZone('America/Los_Angeles'));
echo "Los Angeles Time: " . date_format($datetimeObj, 'H:i:s') . "<br />";

date_timezone_set($datetimeObj, timezone_open('America/New_York'));
echo "New York Time: " . date_format($datetimeObj, 'H:i:s');
?>

Output:

Los Angeles Time: 16:35:00
New York Time: 19:35:00

PHP Version Support:

PHP 5 >= 5.2.0, PHP 7, PHP 8

Summary: PHP date_create() Function

The date_create() function is one of the built-in PHP date and time function. Use this function when you can use DateTime object and want to do date time operations.

Reference:

https://www.php.net/manual/en/function.date-create.php