PHP Date and Time Reference
Choose whether you are representing a local date, a zoned wall-clock time or an instant. Formatting alone cannot resolve that distinction.
How it works
DateTimeImmutable, DateInterval and DateTimeZone give explicit objects for many application tasks. Procedural helpers remain useful, but functions that depend on defaults can hide environment-sensitive behaviour. Fixed elapsed seconds and calendar arithmetic differ across timezone transitions. Parsing must check errors and warnings, not merely whether an object was returned. Locale-oriented deprecated formatting APIs should not become the default design for new code.
Run it locally
Run this complete source locally with PHP 8.2 or newer. Save it using the filename shown and run the command below. PHP is not currently available in Bhylu’s browser playground. Apache and MySQL are not needed for an ordinary CLI example.
php -l ref-time.php
php ref-time.phpDownload this source as a local PHP lab file. Keep lab files separate from the Bhylu project and production data.
Example
<?php
declare(strict_types=1);
$date = new DateTimeImmutable("2026-02-01",new DateTimeZone("UTC"));
echo $date->format("Y-m-t"), "\n";
echo in_array("Asia/Kolkata",DateTimeZone::listIdentifiers(),true) ? "Timezone available\n" : "Missing timezone\n";
Expected result
2026-02-28
Timezone availableThe month-end format uses an explicit date and timezone, so it does not depend on today’s date. The identifier list confirms a supported named timezone rather than inferring rules from an abbreviation. A displayed date is still only one representation of the underlying date/time contract.
Contracts to check
| API or term | Important boundary |
|---|---|
| DateTimeImmutable, DateInterval, DateTimeZone | Prefer explicit immutable date/time and zone contracts. |
| date, gmdate, time, mktime, gmmktime | Understand default/local versus UTC interpretation and platform range. |
| strtotime, date_parse, checkdate | Parsing heuristics are not a substitute for a required format. |
| timezone_identifiers_list, timezone_open | Use named identifiers and account for deployment timezone-data updates. |
| strftime, gmstrftime | Deprecated since PHP 8.1; choose a maintained formatting approach. |
Related API names
This alphabetic inventory helps locate related calls. Availability was checked in the review runtime; it is not a recommendation to use every API or a claim that every overload/function was executed. Read the official entry for version, extension, failure and security details.
| Name | Review-runtime status |
|---|---|
checkdate() | Available in the PHP review runtime |
date() | Available in the PHP review runtime |
date_add() | Available in the PHP review runtime |
date_create() | Available in the PHP review runtime |
date_create_from_format() | Available in the PHP review runtime |
date_date_set() | Available in the PHP review runtime |
date_default_timezone_get() | Available in the PHP review runtime |
date_default_timezone_set() | Available in the PHP review runtime |
date_diff() | Available in the PHP review runtime |
date_format() | Available in the PHP review runtime |
date_get_last_errors() | Available in the PHP review runtime |
date_interval_create_from_date_string() | Available in the PHP review runtime |
date_interval_format() | Available in the PHP review runtime |
date_isodate_set() | Available in the PHP review runtime |
date_modify() | Available in the PHP review runtime |
date_offset_get() | Available in the PHP review runtime |
date_parse() | Available in the PHP review runtime |
date_parse_from_format() | Available in the PHP review runtime |
date_sub() | Available in the PHP review runtime |
date_sun_info() | Available in the PHP review runtime |
date_sunrise() | Available in the PHP review runtime |
date_sunset() | Available in the PHP review runtime |
date_time_set() | Available in the PHP review runtime |
date_timestamp_get() | Available in the PHP review runtime |
date_timestamp_set() | Available in the PHP review runtime |
date_timezone_get() | Available in the PHP review runtime |
date_timezone_set() | Available in the PHP review runtime |
getdate() | Available in the PHP review runtime |
gettimeofday() | Available in the PHP review runtime |
gmdate() | Available in the PHP review runtime |
gmmktime() | Available in the PHP review runtime |
gmstrftime() | Available but deprecated; read the modern alternative |
idate() | Available in the PHP review runtime |
localtime() | Available in the PHP review runtime |
microtime() | Available in the PHP review runtime |
mktime() | Available in the PHP review runtime |
strftime() | Available but deprecated; read the modern alternative |
strptime() | Not available in this review runtime; check version and extension requirements |
strtotime() | Available in the PHP review runtime |
time() | Available in the PHP review runtime |
timezone_abbreviations_list() | Available in the PHP review runtime |
timezone_identifiers_list() | Available in the PHP review runtime |
timezone_location_get() | Available in the PHP review runtime |
timezone_name_from_abbr() | Available in the PHP review runtime |
timezone_name_get() | Available in the PHP review runtime |
timezone_offset_get() | Available in the PHP review runtime |
timezone_open() | Available in the PHP review runtime |
timezone_transitions_get() | Available in the PHP review runtime |
timezone_version_get() | Available in the PHP review runtime |
Check the official PHP manual for detailed version and API contracts.