getdate()

getdate() — Get date/time information.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

Returns an associative array containing the date information of the timestamp, or the current local time if timestamp is omitted or null.

Signature

getdate(?int $timestamp = null): array

Parameters

ParameterTypeWhat it takes
$timestamp?intThe optional timestamp parameter is an int Unix timestamp that defaults to the current local time if timestamp is omitted or null. In other words, it defaults to the value of time().

Return value

Returns an associative array of information related to the timestamp. Elements from the returned associative array are as follows: Key elements of the returned associative array Key Description Example returned values "seconds" Numeric representation of seconds 0 to 59 "minutes" Numeric representation of minutes 0 to 59 "hours" Numeric representation of hours 0 to 23 "mday" Numeric representation of the day of the month 1 to 31 "wday" Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) "mon" Numeric representation of a month 1 through 12 "year" A full numeric representation of a year, 4 digits Examples: 1999 or 2003 "yday" Numeric representation of the day ...

Example

A runnable snippet:

$today = getdate(); print_r($today);

Output:

Array ( [seconds] => 40 [minutes] => 58 [hours] => 21 [mday] => 17 [wday] => 2 [mon] => 6 [year] => 2003 [yday] => 167 [weekday] => Tuesday [month] => June [0] => 1055901520 )

Changelog

VersionChange
8.0.0timestamp is nullable now.

See also

date(), idate(), localtime(), time(), setlocale()

All PHP 8.5 built-in functions

Reference card built from the PHP manual page getdate() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.