WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

PHP 5 Date/Time Functions


PHP Date/Time Introduction

The date/time functions allow you to get the date and time from the server where your PHP script runs. You can then use the date/time functions to format the date and time in several ways.


Installation

The PHP date/time functions are part of the PHP core. No installation is required to use these functions.


Runtime Configuration

The behavior of these functions is affected by settings in php.ini:

Name Description Default PHP Version
date.timezone The default timezone (used by all date/time functions) "" PHP 5.1
date.default_latitude The default latitude (used by date_sunrise() and date_sunset())  "31.7667" PHP 5.0
date.default_longitude The default longitude (used by date_sunrise() and date_sunset()) "35.2333" PHP 5.0
date.sunrise_zenith The default sunrise zenith (used by date_sunrise() and date_sunset()) "90.83" PHP 5.0
date.sunset_zenith The default sunset zenith (used by date_sunrise() and date_sunset()) "90.83" PHP 5.0

PHP 5 Date/Time Functions

function Description
checkdate () Verify the Gregorian date.
date_add () Add day, month, year, hour, minute, and second 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 days.
date_format () Returns a date formatted according to the specified format.
date_get_last_errors () Returns warnings /errors in the date string.
date_interval_create_from_date_string () Creates a DateInterval from the relevant part of the string.
date_interval_format () Format the time interval.
date_isodate_set () Set the ISO date.
date_modify() Modify the timestamp.
date_offset_get () Returns the time zone offset.
date_parse_from_format () Returns an associative array with detailed information for the specified date according to the specified format.
date_parse () Returns an associative array with detailed information for the specified date.
date_sub () Subtracts day, month, year, hour, minute, and second from the specified date.
date_sun_info () Returns an array containing information about sunrise /sunset and dusk start /end of the specified date and place.
date_sunrise () Returns the sunrise time for the specified date and location.
date_sunset () Returns the sunset time for the specified date and location.
date_time_set () Set the time.
date_timestamp_get () Returns the Unix timestamp.
date_timestamp_set () Sets the date and time based on the Unix timestamp.
date_timezone_get () Returns the time zone of the given DateTime object.
date_timezone_set () Sets the time zone of the DateTime object.
date () Format local date and time.
getdate () Returns date /time information for a timestamp or the current local date /time.
gettimeofday () Returns the current time.
gmdate () Format GMT /UTC date and time.
gmmktime () Returns the UNIX timestamp of the GMT date.
gmstrftime () Formats GMT /UTC date and time according to locale settings.
idate() Format the local time /date as an integer.
localtime () Return to local time.
microtime () Returns the microseconds of the current Unix timestamp.
mktime () Returns a Unix timestamp of a date.
strftime () Format local time /date according to locale.
strptime () Parse the time /date generated by strftime ().
strtotime () Parse a date or time description of any English text 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 the 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 from GMT.
timezone_open () Creates a new DateTimeZone object.
timezone_transitions_get () Returns all conversions for the time zone.
timezone_version_get () Returns the version of the time zone database.

PHP 5 Predefined Date/Time Constants

Constant Description
DATE_ISO8601 ISO-8601 (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 (Sun, 14 Aug 2005 16:13:03 +0000)
DATE_RSS RSS (Sun, 14 Aug 2005 16:13:03 UTC)