Hostgre


HomeReferencePHPPHP 5 Date/Time Functions

PHP 5 Date/Time Functions

Introduction

The date/time functions enable you to get the date and time from the server wherever your PHP script runs. you'll then use the date/time functions to format the date and time in many ways that. Note: These functions rely on the locale settings of your server. keep in mind to require daylight-saving time time and leap years into consideration once operating with these functions.

Installation

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

Runtime Configuration

The behavior of those functions is affected by settings in php.ini:
NameDescriptionDefaultPHP Version
date.timezoneThe default timezone (used by all date/time functions)""PHP 5.1
date.default_latitudeThe default latitude (used by date_sunrise() and date_sunset()) "31.7667"PHP 5.0
date.default_longitudeThe default longitude (used by date_sunrise() and date_sunset())"35.2333"PHP 5.0
date.sunrise_zenithThe default sunrise zenith (used by date_sunrise() and date_sunset())"90.83"PHP 5.0
date.sunset_zenithThe default sunset zenith (used by date_sunrise() and date_sunset())"90.83"PHP 5.0

PHP 5 Date/Time Functions

FunctionDescription
checkdate()Validates a Gregorian date
date_add()Adds days, months, years, hours, minutes, and seconds to a date
date_create_from_format()Return a new DateTime object formatted according to a specified format
date_create()Return a new DateTime object
date_date_set()Set a new date
date_default_timezone_get()Return the default timezone used by all date/time functions
date_default_timezone_set()Set the default timezone used by all date/time functions
date_diff()Return the difference between two dates
date_format()Return a date formatted according to a specified format
date_get_last_errors()Return the warnings/errors found in a date string
date_interval_create_from_date_string()Set up a DateInterval from the relative parts of the string
date_interval_format()Formats the interval
date_isodate_set()Set the ISO date
date_modify()Modifies the timestamp
date_offset_get()Return the timezone offset
date_parse_from_format()Return an associative array with detailed info about a specified date, according to a specified format
date_parse()Return an associative array with detailed info about a specified date
date_sub()Subtracts days, months, years, hours, minutes, and seconds from a date
date_sun_info()Return an array containing info about sunset/sunrise and twilight begin/end, for a specified day and location
date_sunrise()Return the sunrise time for a specified day and location
date_sunset()Return the sunset time for a specified day and location
date_time_set()Set the time
date_timestamp_get()Return the Unix timestamp
date_timestamp_set()Set the date and time based on a Unix timestamp
date_timezone_get()Return the time zone of the given DateTime object
date_timezone_set()Set the time zone for the DateTime object
date()Formats a local date and time
getdate()Return date/time information of a timestamp or the current local date/time
gettimeofday()Return the current time
gmdate()Formats a GMT/UTC date and time
gmmktime()Return the Unix timestamp for a GMT date
gmstrftime()Formats a GMT/UTC date and time according to locale settings
idate()Formats a local time/date as integer
localtime()Return the local time
microtime()Return the current Unix timestamp with microseconds
mktime()Return the Unix timestamp for a date
strftime()Formats a local time and/or date according to locale settings
strptime()Parses a time/date generated with strftime()
strtotime()Parses an English textual datetime into a Unix timestamp
time()Return the current time as a Unix timestamp
timezone_abbreviations_list()Return an associative array containing dst, offset, and the timezone name
timezone_identifiers_list()Return an indexed array with all timezone identifiers
timezone_location_get()Return location information for a specified timezone
timezone_name_from_ abbr()Return the timezone name from abbreviation
timezone_name_get()Return the name of the timezone
timezone_offset_get()Return the timezone offset from GMT
timezone_open()Create new DateTimeZone object
timezone_transitions_get()Return all transitions for the timezone
timezone_version_get()Return the version of the timezone db

PHP 5

Time Constants / Predefined Date

ConstantDescription
DATE_ATOMAtom (2015-08-22T16:13:03+0000)
DATE_COOKIEHTTP Cookies (Sat, 22 Aug 2005 16:13:03 UTC)
DATE_ISO8601ISO-8601 (2015-08-22T16:13:03+0000)
DATE_RFC822RFC 822 (Sat, 22 Aug 2015 16:13:03 UTC)
DATE_RFC850RFC 850 (Saturday, 22-Aug-15 16:13:03 UTC)
DATE_RFC1036RFC 1036 (Saturday, 22-Aug-15 16:13:03 UTC)
DATE_RFC1123RFC 1123 (Sat, 22 Aug 2015 16:13:03 UTC)
DATE_RFC2822RFC 2822 (Sat, 22 Aug 2015 16:13:03 +0000)
DATE_RSSRSS (Sat, 22 Aug 2015 16:13:03 UTC)
DATE_W3CWorld Wide Web Consortium (2015-08-22T16:13:03+0000)