Here you will find PHP time and date functions to get the server time when the PHP script executes on it. These functions also allow you to get the date and time in several formats.
PHP date/time functions do not require any library to install. These functions come built-in with the PHP language.
Note: While working with the PHP date and time functions, always keep the daylight savings and leap years into consideration for the exact output. Also, server settings can affect the working of some methods.
Runtime Configurations
These functions depend on the configurations in the PHP.ini file.
Name | Description | Default Value |
---|---|---|
date.timezone | Gives the default timezone used by all the time/date functions in PHP | “” |
date.default_latitude | date_sunrise() and date_sunset() method use the latitude which is returned by this method | “31.7667” |
date.default_longitude | date_sunrise() and date_sunset() method use the longitude which is returned by this method | “35.2333” |
date.sunrise_zenith | date_sunrise() and date_sunset() method use the sunrise zenith which is returned by this method | “90.83” |
date.sunset_zenith | date_sunrise() and date_sunset() method use the sunset zenith which is returned by this method | “90.83” |
PHP Date/Time Functions
Function | Description |
---|---|
checkdate() | Check if a Gregorian date is valid |
date_add() | Add days, months, years, hours, minutes, and seconds in the date returned by the PHP function |
date_create_from_format() | Specify format and return new DateTime object in that format |
date_create() | Create new DateTime object |
date_date_set() | Set a new date |
date_default_timezone_get() | Get Default timezone currently being used by the time/date functions |
date_default_timezone_set() | Set Default timezone currently being used by the time/date functions |
date_diff() | Gives the difference between the two dates. The difference can also be in the form of date format |
date_format() | Specify format and return new DateTime object in that format |
date_get_last_errors() | If the date string contains any string, this function will return the error |
date_interval_create_from_date_string() | Create dateInterval from the date string |
date_interval_format() | Format dateInterval |
date_isodate_set() | Set ISO dates |
date_modify() | Change/Update the Timestamp |
date_offset_get() | Get the timezone offset |
date_parse_from_format() | Returns an associative array with a specified date to a specific format |
date_parse() | Get information about a date in the form of an associative array |
date_sub() | Subtracts/minus days, months, years, hours, minutes, and seconds from a PHP date |
date_sun_info() | Get the sunset/sunrise and twilight begin/end information for a specific day and location in the form of an associative array |
date_sunrise() | Get the sunrise time for the specified location and day |
date_sunset() | Get the sunset time for the specified location and day |
date_time_set() | Set time in PHP |
date_timestamp_get() | Get Unix timestamp in PHP |
date_timestamp_set() | Set the time and date using unix timestamp |
date_timezone_get() | Get the time zone of the DateTime object |
date_timezone_set() | Set the time zone of the DateTime object |
date() | Format local date and time |
getdate() | Get time/date information for the current local time/date or timestamp |
gettimeofday() | Get the current time of the day |
gmdate() | Format GMT/UTC time and date |
gmmktime() | Get the Unix timestamp for the date that is in GMT format |
gmstrftime() | Format a UTC/GMT time and date (depends on locale configurations) |
idate() | Get local date/time as an integer |
localtime() | Get the local time |
microtime() | Get the current Unix timestamp (microseconds) |
mktime() | Get the Unix timestamp of the date |
strftime() | Format a local time/date (depends on locale configurations) |
strptime() | Parse date/time obtained with strftime() function |
strtotime() | Parses DateTime from textual format into a Unix timestamp |
time() | Get the current time in Unix timestamp form |
timezone_abbreviations_list() | Get the dst, offset, and timezone name in the form of an associative array |
timezone_identifiers_list() | Get an array of all timezone identifiers |
timezone_location_get() | Get location information according to the timezone |
timezone_name_from_ abbr() | Get the timezone name using abbreviation |
timezone_name_get() | Get the name of the timezone |
timezone_offset_get() | Get the timezone offset (GMT) |
timezone_open() | Create new DateTimeZone object |
timezone_transitions_get() | Get all transitions for the timezone |
timezone_version_get() | Get the version of the timezonedb |