PHP getdate() Function: Retrieve Date and Time Information

The PHP getdate() function returns an associative array with detailed date and time components based on a provided Unix timestamp or the current local time, explaining its parameters, return structure, and offering a practical code example with sample output.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP getdate() Function: Retrieve Date and Time Information

The getdate() function in PHP returns an associative array containing date and time information derived from a given Unix timestamp, or the current local time if no timestamp is provided.

Parameters timestamp (optional) – an integer Unix timestamp; if omitted, the function uses the current time returned by time().

Return value

An associative array with keys such as seconds, minutes, hours, mday, wday, mon, year, etc., representing the corresponding components of the date and time.

Example

<?php
$today = getdate();
print_r($today);
?>

Sample output

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

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

date-timegetdatephp-functions
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.