The PHP Date and Time functions lets you get date & time from the server where your PHP scripts are running. You can use these functions in formatting date and time in so many different ways.
Installation
Runtime Configuration
Date and 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 |
List of PHP Date and Time Functions
Sr.No | Function & Description | PHP |
---|---|---|
1 | checkdate() Validates a Gregorian date | 3 |
2 | date_create() Returns new DateTime object | 5 |
3 | date_date_set() Sets the date | 5 |
4 | date_default_timezone_get() Returns the default time zone | 5 |
5 | date_default_timezone_set() Sets the default time zone | 5 |
6 | date_format() Returns date formatted according to given format | 5 |
7 | date_isodate_set() Sets the ISO date | 5 |
8 | date_modify() Alters the timestamp | 5 |
9 | date_offset_get() Returns the daylight saving time offset | 5 |
10 | date_parse() Returns associative array with detailed info about given date | 5 |
11 | date_sun_info() Returns an array with information about sunset/sunrise and twilight begin/end. | 5 |
12 | date_sunrise() Returns the time of sunrise for a given day / location | 5 |
13 | date_sunset() Returns the time of sunset for a given day / location | 5 |
14 | date_time_set() Sets the time | 5 |
15 | date_timezone_get() Return time zone relative to given DateTime | 5 |
16 | date_timezone_set() Sets the time zone for the DateTime object | 5 |
17 | date() Formats a local time/date | 3 |
18 | getdate() Returns an array that contains date and time information for a Unix timestamp | 3 |
19 | gettimeofday() Returns an array that contains current time information | 3 |
20 | gmdate() Formats a GMT/UTC date/time | 3 |
21 | gmmktime() Returns the Unix timestamp for a GMT date | 3 |
22 | gmstrftime() Formats a GMT/UTC time/date according to locale settings | 3 |
23 | idate() Formats a local time/date as integer | 5 |
24 | localtime() Returns an array that contains the time components of a Unix timestamp | 4 |
25 | microtime() Returns the microseconds for the current time | 3 |
26 | mktime() Returns the Unix timestamp for a date | 3 |
27 | strftime() Formats a local time/date according to locale settings | 3 |
28 | strptime() Parses a time/date generated with strftime() | 5 |
29 | strtotime() Parses an English textual date or time into a Unix timestamp | 3 |
30 | time() Returns the current time as a Unix timestamp | 3 |
31 | timezone_abbreviations_list() Returns associative array containing dst, offset and the timezone name | 5 |
32 | timezone_identifiers_list() Returns numerically index array with all timezone identifiers | 5 |
33 | timezone_name_from_abbr() Returns the timezone name from abbrevation | 5 |
34 | timezone_name_get() Returns the name of the timezone | 5 |
35 | timezone_offset_get() Returns the timezone offset from GMT | 5 |
36 | timezone_open() Returns new DateTimeZone object | 5 |
37 | timezone_transitions_get() Returns all transitions for the timezone | 5 |
38 | date_add() Adds an interval to a date. | 5.3 |
39 | date_create_from_format() Creates a date by parsing a timestring according to a specified format. | 5.3 |
40 | date_diff() Calculates and returns the difference between two dates. | 5.3 |
41 | date_parse_from_format() Returns information about the given date according to the specified format. | 5.3 |
42 | date_parse() Returns an array congaing info about the given date. | 5.2 |
43 | date_sub() Subtracts a time interval from a DateTime object. | 5.3 |
44 | date_timestamp_get() Returns the Unix timestamp | 5.3 |
45 | date_timestamp_set() Sets the date and time value as per the given timestamp. | 5.3 |
46 | date_get_last_errors() Returns warnings and errors while creating a DateTime object. | 5.3 |
47 | date_interval_create_from_date_string() Creates a date interval from a given string. | 5 |
48 | date_interval_format() Formats the given interval. | 5.5 |
49 | date_create_immutable_from_format() Parses a timestring based on specified format. | 5.5 |
50 | date_create_immutable() Creates and returns a DateTimeImmutable object. | 5.5 |
51 | timezone_version_get() Returns the version of the current timezonedb. |
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 ) |
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.