The Date/Time function allows you to get the date and time from the server where the PHP script is running. You can use the Date/Time functions to format dates and times in different ways.
Note: These functions rely on the local settings of the server. Remember to take daylight saving time and leap years into account when using these functions.
The PHP Date/Time functions are an integral part of PHP core. No installation is required to use these functions.
The behavior of Date/Time functions is affected by settings in php.ini:
| name | describe | default | PHP version |
|---|---|---|---|
| date.timezone | Specify the default time zone (all Date/Time functions use this option) | "" | PHP 5.1 |
| date.default_latitude | Specifies the default latitude (date_sunrise() and date_sunset() use this option) | "31.7667" | PHP 5.0 |
| date.default_longitude | Specifies the default longitude (date_sunrise() and date_sunset() use this option) | "35.2333" | PHP 5.0 |
| date.sunrise_zenith | Specifies the default sunrise zenith (date_sunrise() and date_sunset() use this option) | "90.83" | PHP 5.0 |
| date.sunset_zenith | Specifies the default sunset zenith (date_sunrise() and date_sunset() use this option) | "90.83" | PHP 5.0 |
| function | describe |
|---|---|
| checkdate() | Verification of Gregorian dates. |
| date_add() | Add day, month, year, hours, minutes and seconds to a date. |
| date_create_from_format() | Returns a new DateTime object formatted according to the specified format. |
| date_create() | Returns a new DateTime object. |
| date_date_set() | Set a new date. |
| date_default_timezone_get() | Returns the default time zone used by all Date/Time functions. |
| date_default_timezone_set() | Sets the default time zone, used by all Date/Time functions. |
| date_diff() | Returns the difference between two dates. |
| date_format() | Returns a date formatted according to the specified format. |
| date_get_last_errors() | Returns warnings/errors in a date string. |
| date_interval_create_from_date_string() | Builds a DateInterval from the relevant part of the string. |
| date_interval_format() | Format time interval. |
| date_isodate_set() | Set ISO date. |
| date_modify() | Modify timestamp. |
| date_offset_get() | Returns the time zone offset. |
| date_parse_from_format() | Returns an associative array with details for the specified date according to the specified format. |
| date_parse() | Returns an associative array with details for a specified date. |
| date_sub() | Subtracts the day, month, year, hours, minutes, and seconds from the specified date. |
| date_sun_info() | Returns an array containing information about sunrise/sunset and dusk start/dusk end for the specified date and location. |
| date_sunrise() | Returns the sunrise time for a specified date and location. |
| date_sunset() | Returns the sunset time for the specified date and location. |
| date_time_set() | Set time. |
| date_timestamp_get() | Returns the Unix timestamp. |
| date_timestamp_set() | Sets the date and time based on a Unix timestamp. |
| date_timezone_get() | Returns the time zone of the given DateTime object. |
| date_timezone_set() | Sets the time zone of a DateTime object. |
| date() | Format local date and time. |
| getdate() | Returns a timestamp or the date/time information of the current local date/time. |
| gettimeofday() | Returns the current time. |
| gmdate() | Format GMT/UTC date and time. |
| gmmktime() | Returns the UNIX timestamp of a GMT date. |
| gmstrftime() | Format GMT/UTC date and time according to locale settings. |
| idate() | Format local time/date as integer. |
| localtime() | Return local time. |
| microtime() | Returns the number of microseconds in the current Unix timestamp. |
| mktime() | Returns the Unix timestamp of a date. |
| strftime() | Format local time/date according to locale settings. |
| strptime() | Parse the time/date generated by strftime(). |
| strtotime() | Parses any English text date or time description into a Unix timestamp. |
| time() | Returns the Unix timestamp of the current time. |
| timezone_abbreviations_list() | Returns an associative array containing daylight saving time, offset, and time zone name. |
| timezone_identifiers_list() | Returns a numeric array with all time zone identifiers. |
| timezone_location_get() | Returns location information for the specified time zone. |
| timezone_name_from_abbr() | Returns the time zone name based on the time zone abbreviation. |
| timezone_name_get() | Returns the name of the time zone. |
| timezone_offset_get() | Returns the time zone offset relative to GMT. |
| timezone_open() | Create a new DateTimeZone object. |
| timezone_transitions_get() | Returns all conversions for time zones. |
| timezone_version_get() | Returns the version of the time zone database. |
| constant | describe |
|---|---|
| DATE_ATOM | Atom (for example: 2005-08-15T16:13:03+0000) |
| DATE_COOKIE | HTTP Cookies (Example: Sun, 14 Aug 2005 16:13:03 UTC) |
| DATE_ISO8601 | ISO-8601 (for example: 2005-08-14T16:13:03+0000) |
| DATE_RFC822 | RFC 822 (Example: Sun, 14 Aug 2005 16:13:03 UTC) |
| DATE_RFC850 | RFC 850 (Example: Sunday, 14-Aug-05 16:13:03 UTC) |
| DATE_RFC1036 | RFC 1036 (Example: Sunday, 14-Aug-05 16:13:03 UTC) |
| DATE_RFC1123 | RFC 1123 (Example: Sun, 14 Aug 2005 16:13:03 UTC) |
| DATE_RFC2822 | RFC 2822 (Example: Sun, 14 Aug 2005 16:13:03 +0000) |
| DATE_RSS | RSS (Example: Sun, 14 Aug 2005 16:13:03 UTC) |
| DATE_W3C | World Wide Web Consortium (for example: 2005-08-14T16:13:03+0000) |