PHP getdate() Function

What is PHP getdate() Function?

If you want to get detail of current local date-time or a specific timestamp, use getdate() function. the function lets you know the following detail-

KeyDescriptionExample
secondsNumeric seconds0 to 59
minutesNumeric minutes0 to 59
hoursNumeric hours0 to 23
mdayDay of the month1 to 31
wdayDay of the week (0 = Sunday,  6 = Saturday)0 to 6
monNumeric month1 to 12
year4-digit Numeric yeare.g., 2024
ydayDay of the year (0-indexed)0 to 365
weekdayFull textual day of the week“Sunday” to “Saturday”
monthFull textual of the month“January” to “December”
0Seconds since the Unix Epoch (the timestamp)1768024581

Syntax:

gatedate(timestamp)

Parameters:

The function has 1 parameter which is optional-

timestamp (Optional): It specifies a timestamp. If the timestamp is omitted, it becomes current local time.

Return Values:

The function returns an associative array which contains detail (See the table above) of a date-time.

Examples:

Example 1:

<pre>
<?php
$today = getdate();
echo "Current local date-time detail is-<br />";
print_r($today);
?>

Output:

Current local date-time detail is-
Array
(
[seconds] => 46
[minutes] => 27
[hours] => 7
[mday] => 10
[wday] => 6
[mon] => 1
[year] => 2026
[yday] => 9
[weekday] => Saturday
[month] => January
[0] => 1768026466
)

Example 2:

<pre>
<?php
date_default_timezone_set("America/Los_Angeles");
$LosAngelesTimestamp = time();
$LosAngelesTimeDetail = getdate($LosAngelesTimestamp);
echo "Current local Los Angeles date-time detail is-<br />";
print_r($LosAngelesTimeDetail);
?>
</pre>

Output:

Current local Los Angeles date-time detail is-
Array
(
[seconds] => 46
[minutes] => 27
[hours] => 22
[mday] => 9
[wday] => 5
[mon] => 1
[year] => 2026
[yday] => 8
[weekday] => Friday
[month] => January
[0] => 1768026466
)

Example 3:

<pre>
<?php
$timestamp = strtotime("2026-01-10 12:52:00");
$dateTimeDetail = getdate($timestamp);
echo "Current local date-time detail of \"2026-09-01 12:52:00\" is-<br />";
print_r($dateTimeDetail);
?>
</pre>

Output:

Current local date-time detail of "2026-09-01 12:52:00" is-
Array
(
[seconds] => 0
[minutes] => 52
[hours] => 12
[mday] => 10
[wday] => 6
[mon] => 1
[year] => 2026
[yday] => 9
[weekday] => Saturday
[month] => January
[0] => 1768078320
)

PHP Version Support:

PHP 4, PHP 5, PHP 7, PHP 8

Summary: PHP getdate() Function

The getdate() function may be the most commonly used built-in PHP date and time function. To know the detail of a date-time, use this function.

Reference:

https://www.php.net/manual/en/function.getdate.php