PHP - Date & Time Functions
These functions allow you to get the date and time from the server where your
PHP scripts are running. You can use these functions to format the date and
time in many different ways.
Installation
There is no installation needed to use these functions; they are part of the PHP
core.
Runtime Configuration
The behavior of the these functions is affected by settings in php.ini. All these
parameters are available in PHP version 5 and onwards.
Date/Time configuration options:
Name Default Description Changeable
date.default_latitude "31.7667" Specifies the default latitude. PHP_INI_ALL
date.default_longitude "35.2333" Specifies the default longitude PHP_INI_ALL
date.sunrise_zenith "90.83" Specifies the default sunrise zenith PHP_INI_ALL
date.sunset_zenith "90.83" Specifies the default sunset zenith PHP_INI_ALL
date.timezone "" Specifies the default timezone PHP_INI_ALL
PHP − indicates the earliest version of PHP that supports the function.
Sr.No Function & Description PHP
checkdate()
1 3
Validates a Gregorian date
date_create()
2 5
Returns new DateTime object
date_date_set()
3 5
Sets the date
date_default_timezone_get()
4 5
Returns the default time zone
date_default_timezone_set()
5 5
Sets the default time zone
date_format()
6 5
Returns date formatted according to given format
date_isodate_set()
7 5
Sets the ISO date
date_modify()
8 5
Alters the timestamp
date_offset_get()
9 5
Returns the daylight saving time offset
date_parse()
10 5
Returns associative array with detailed info about given date
date_sun_info()
11 5
Returns an array with information about sunset/sunrise and twilight begin/end.
date_sunrise()
12 5
Returns the time of sunrise for a given day / location
date_sunset()
13 5
Returns the time of sunset for a given day / location
date_time_set()
14 5
Sets the time
date_timezone_get()
15 5
Return time zone relative to given DateTime
date_timezone_set()
16 5
Sets the time zone for the DateTime object
date()
17 3
Formats a local time/date
getdate()
18 3
Returns an array that contains date and time information for a Unix timestamp
gettimeofday()
19 3
Returns an array that contains current time information
gmdate()
20 3
Formats a GMT/UTC date/time
gmmktime()
21 3
Returns the Unix timestamp for a GMT date
gmstrftime()
22 3
Formats a GMT/UTC time/date according to locale settings
idate()
23 5
Formats a local time/date as integer
localtime()
24 4
Returns an array that contains the time components of a Unix timestamp
microtime()
25 3
Returns the microseconds for the current time
mktime()
26 3
Returns the Unix timestamp for a date
strftime()
27 3
Formats a local time/date according to locale settings
strptime()
28 5
Parses a time/date generated with strftime()
strtotime()
29 3
Parses an English textual date or time into a Unix timestamp
time()
30 3
Returns the current time as a Unix timestamp
timezone_abbreviations_list()
31 5
Returns associative array containing dst, offset and the timezone name
timezone_identifiers_list()
32 5
Returns numerically index array with all timezone identifiers
timezone_name_from_abbr()
33 5
Returns the timezone name from abbrevation
timezone_name_get()
34 5
Returns the name of the timezone
timezone_offset_get()
35 5
Returns the timezone offset from GMT
timezone_open()
36 5
Returns new DateTimeZone object
timezone_transitions_get()
37 5
Returns all transitions for the timezone
date_add()
38 5.3
Adds an interval to a date.
date_create_from_format()
39 5.3
Creates a date by parsing a timestring according to a specified format.
date_diff()
40 5.3
Calculates and returns the difference between two dates.
date_parse_from_format()
41 5.3
Returns information about the given date according to the specified format.
date_parse()
42 5.2
Returns an array congaing info about the given date.
date_sub()
43 5.3
Subtracts a time interval from a DateTime object.
date_timestamp_get()
44 5.3
Returns the Unix timestamp
date_timestamp_set()
45 5.3
Sets the date and time value as per the given timestamp.
date_get_last_errors()
46 5.3
Returns warnings and errors while creating a DateTime object.
date_interval_create_from_date_string()
47 5
Creates a date interval from a given string.
date_interval_format()
48 5.5
Formats the given interval.
date_create_immutable_from_format()
49 5.5
Parses a timestring based on specified format.
date_create_immutable()
50 5.5
Creates and returns a DateTimeImmutable object.
timezone_version_get()
51 5.3
Returns the version of the current timezonedb.
Explore our latest online courses and learn new skills at your own pace. Enroll and
become a certified expert to boost your career.
PHP Date / Time Constants
Sr.No Constant & Description
1 DATE_ATOM
Atom (example: 2005-08-15T16:13:03+0000)
2 DATE_COOKIE
HTTP Cookies (example: Sun, 14 Aug 2005 16:13:03 UTC)
3 DATE_ISO8601
ISO-8601 (example: 2005-08-14T16:13:03+0000)
4 DATE_RFC822
RFC 822 (example: Sun, 14 Aug 2005 16:13:03 UTC)
5 DATE_RFC850
RFC 850 (example: Sunday, 14-Aug-05 16:13:03 UTC)
6 DATE_RFC1036
RFC 1036 (example: Sunday, 14-Aug-05 16:13:03 UTC)
7 DATE_RFC1123RFC
RFC 1123 (example: Sun, 14 Aug 2005 16:13:03 UTC)
8 DATE_RFC2822
RFC 2822 (Sun, 14 Aug 2005 16:13:03 +0000)
9 DATE_RSS
RSS (Sun, 14 Aug 2005 16:13:03 UTC)
10 DATE_W3C
World Wide Web Consortium (example: 2005-08-14T16:13:03+0000)
11 SUNFUNCS_RET_TIMESTAMP
Timestamp ( Available in 5.1.2 )
12 SUNFUNCS_RET_STRING
Hours:minutes (example: 08:02) ( Available in 5.1.2 )
13 SUNFUNCS_RET_DOUBLE
Hours as floating point number (example 8.75)( Available in 5.1.2 )