PHP Function Reference

PHP getdate() Function



The PHP getdate() function returns an associative array containing the date information of the timestamp, or the current local time if timestamp is omitted or null.

Syntax

getdate(timestamp)

Parameters

timestamp Optional. Specify the Unix timestamp representing the date. If it is omitted or null, it defaults to the current local time.

Return Value

Returns an associative array of information related to the timestamp. Elements from the returned associative array are as follows:

KeysDescriptionExample returned values
"seconds"Numeric representation of seconds0 to 59
"minutes"Numeric representation of minutes0 to 59
"hours"Numeric representation of hours0 to 23
"mday"Numeric representation of the day of the month1 to 31
"wday"Numeric representation of the day of the week0 (for Sunday) through 6 (for Saturday)
"mon"Numeric representation of a month1 through 12
"year"A full numeric representation of a year, 4 digitsExamples: 1999 or 2003
"yday"Numeric representation of the day of the year0 through 365
"weekday"A full textual representation of the day of the weekSunday through Saturday
"month"A full textual representation of a monthJanuary through December
0Seconds since the Unix Epoch.System Dependent, typically -2147483648 through 2147483647.

Example: using current local time

The example below shows how to get the date information for current local time.

<?php
  //date information of current local time
  print_r(getdate());
?>

The output of the above code will be:

Array
(
    [seconds] => 29
    [minutes] => 12
    [hours] => 14
    [mday] => 13
    [wday] => 1
    [mon] => 9
    [year] => 2021
    [yday] => 255
    [weekday] => Monday
    [month] => September
    [0] => 1631542349
)

Example: using specified timestamp

In the example below this function is used to get the date information of the specified timestamp.

<?php
  //date information of specified timestamp
  print_r(getdate(1307297845));
?>

The output of the above code will be:

Array
(
    [seconds] => 25
    [minutes] => 17
    [hours] => 18
    [mday] => 5
    [wday] => 0
    [mon] => 6
    [year] => 2011
    [yday] => 155
    [weekday] => Sunday
    [month] => June
    [0] => 1307297845
)

❮ PHP Date and Time Reference