getdate

Get date/time information

Syntax

getdate ( int|null $timestamp = null ) : array

Parameters

timestamp

The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

Return

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

Key Description Example
"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 a day of the month 1 to 31
"wday" Numeric representation of a day of the week 0 to 6
"mon" Numeric representation of a month 1 to 12
"year" Numeric representation of a year 0000 to 9999
"yday" Numeric representation of a day of the year 0 to 365
"weekday" Textual representation of a day of the week Sunday to Saturday
"month" Textual representation of a month January to December
0 Seconds since the Unix Epoch System Dependent (typically -2147483648 to 2147483647)

Examples

void

<?

$return = getdate();

print_r($return);

?>
Array
(
    [seconds] => 53
    [minutes] => 19
    [hours] => 16
    [mday] => 24
    [wday] => 0
    [mon] => 10
    [year] => 2021
    [yday] => 296
    [weekday] => Sunday
    [month] => October
    [0] => 1635092393
)

timestamp

<?

$hour = 4;
$minute = 5;
$second = 6;
$month = 2;
$day = 3;
$year = 2001;

$timestamp = mktime($hour, $minute, $second, $month, $day, $year);

$return = getdate($timestamp);

print_r($return);

?>
Array
(
    [seconds] => 6
    [minutes] => 5
    [hours] => 4
    [mday] => 3
    [wday] => 6
    [mon] => 2
    [year] => 2001
    [yday] => 33
    [weekday] => Saturday
    [month] => February
    [0] => 981173106
)

PHP

Home Menu