DateTime::__construct - Returns new DateTime object
Code Examples

date_create( [string$datetime = "now"], [DateTimeZone|null$timezone = null] ): DateTime|false

Returns new DateTime object.



A date/time string. Valid formats are explained in Date and Time Formats.

Enter "now" here to obtain the current time when using the $timezone parameter.


A DateTimeZone object representing the timezone of $datetime.

If $timezone is omitted or null, the current timezone will be used.


The $timezone parameter and the current timezone are ignored when the $datetime parameter either is a UNIX timestamp (e.g. @946684800) or specifies a timezone (e.g. 2010-01-28T15:00:00+02:00).

Return Values

Returns a new DateTime instance. Procedural style returns false on failure.

Exceptions and Errors

Emits Exception in case of an error.


Version Description
7.1.0 From now on microseconds are filled with actual value. Not with '00000'.

Related Functions

Example of DateTime::__construct

Show all examples for DateTime::__construct

PHP Version:

Function DateTime::__construct:

Date and Time Functions

Most used PHP functions