PHP Date & Time
ADVERTISEMENTS
PHP date() function allows you to get the locale date and date-time from the server where your PHP scripts are running.
Example to print a date
<?php
echo date('Y-m-d');
?>
Output
2020-06-04
Example to print date with time
<?php
echo date('Y-m-d H:i:s');
?>
Output
2020-06-04 09:41:10
Definition
- The date() function allows you to get the locale date and date-time from the server where your PHP scripts are running.
- There are you can set the format of date and date in many ways.
- The data of date and time is stored in 64-bit numbers.
Note: Always remember these all date functions are dependent on your locale server settings.
Requirements
No external libraries are needed to build this extension.
Installation
There is no installation needed to use these functions; they are part of the PHP core.
Runtime Configuration
The behavior of these functions is affected by settings in php.ini.
Date/Time Configuration Options
Name | Default | Changeable | Changelog |
---|---|---|---|
date.default_latitude | "31.7667" | PHP_INI_ALL | Available since PHP 5.0.0. |
date.default_longitude | "35.2333" | PHP_INI_ALL | Available since PHP 5.0.0. |
date.sunrise_zenith | "90.583333" | PHP_INI_ALL | Available since PHP 5.0.0. |
date.sunset_zenith | "90.583333" | PHP_INI_ALL | Available since PHP 5.0.0. |
date.timezone | "" | PHP_INI_ALL | Available since PHP 5.1.0. |
Resource Types
This extension has no resource types defined.
Predefined Constants
PHP provided some predefined date constants
- SUNFUNCS_RET_TIMESTAMP - (integer) Timestamp
- SUNFUNCS_RET_STRING - (integer) Hours: minutes (example: 08:02)
- SUNFUNCS_RET_DOUBLE - (integer) Hours as a floating-point number (example 8.75)
Date Functions
- checkdate — Validate a Gregorian date
- date_add — Alias of DateTime::add
- date_create_from_format — Alias of DateTime::createFromFormat
- date_create_immutable_from_format — Alias of DateTimeImmutable::createFromFormat
- date_create_immutable — Alias of DateTimeImmutable::__construct
- date_create — Alias of DateTime::__construct
- date_date_set — Alias of DateTime::setDate
- date_default_timezone_get — Gets the default timezone used by all date/time functions in a script
- date_default_timezone_set — Sets the default timezone used by all date/time functions in a script
- date_diff — Alias of DateTime::diff
- date_format — Alias of DateTime::format
- date_get_last_errors — Alias of DateTime::getLastErrors
- date_interval_create_from_date_string — Alias of DateInterval::createFromDateString
- date_interval_format — Alias of DateInterval::format
- date_isodate_set — Alias of DateTime::setISODate
- date_modify — Alias of DateTime::modify
- date_offset_get — Alias of DateTime::getOffset
- date_parse_from_format — Get info about given date formatted according to the specified format
- date_parse — Returns associative array with detailed info about given date
- date_sub — Alias of DateTime::sub
- date_sun_info — Returns an array with information about sunset/sunrise and twilight begin/end
- date_sunrise — Returns time of sunrise for a given day and location
- date_sunset — Returns time of sunset for a given day and location
- date_time_set — Alias of DateTime::setTime
- date_timestamp_get — Alias of DateTime::getTimestamp
- date_timestamp_set — Alias of DateTime::setTimestamp
- date_timezone_get — Alias of DateTime::getTimezone
- date_timezone_set — Alias of DateTime::setTimezone
- date — Format a local time/date
- getdate — Get date/time information
- gettimeofday — Get current time
- gmdate — Format a GMT/UTC date/time
- gmmktime — Get Unix timestamp for a GMT date
- gmstrftime — Format a GMT/UTC time/date according to locale settings
- idate — Format a local time/date as integer
- localtime — Get the local time
- microtime — Return current Unix timestamp with microseconds
- mktime — Get Unix timestamp for a date
- strftime — Format a local time/date according to locale settings
- strptime — Parse a time/date generated with strftime
- strtotime — Parse about any English textual datetime description into a Unix timestamp
- time — Return current Unix timestamp
- timezone_abbreviations_list — Alias of DateTimeZone::listAbbreviations
- timezone_identifiers_list — Alias of DateTimeZone::listIdentifiers
- timezone_location_get — Alias of DateTimeZone::getLocation
- timezone_name_from_abbr — Returns the timezone name from abbreviation
- timezone_name_get — Alias of DateTimeZone::getName
- timezone_offset_get — Alias of DateTimeZone::getOffset
- timezone_open — Alias of DateTimeZone::__construct
- timezone_transitions_get — Alias of DateTimeZone::getTransitions
- timezone_version_get — Gets the version of the timezonedb