The getdate() function is used to get information about a particular date/time. It accepts an optional parameter specifying the time stamp of which you need the info about. If you haven't passed any argument, this function returns information about the current local time.
getdate([$timestamp])
Sr.No | Parameter & Description |
---|---|
1 |
timestamp
(Optional)This represents the timestamp specifying the time/date about which you need the information. |
PHP getdate() function returns an array containing the information about the given time/date.
This function was first introduced in PHP Version 4 and, works with all the later versions.
Following example demonstrates the usage of the getdate() function −
<?php $info = getdate(); print_r($info); ?>
This will produce following result −
Array ( [seconds] => 34 [minutes] => 52 [hours] => 12 [mday] => 8 [wday] => 5 [mon] => 5 [year] => 2020 [yday] => 128 [weekday] => Friday [month] => May [0] => 1588942354 )
Now, lets try passing a timestamp to this function −
<?php $timestamp = time()-(23*12*30); $info = getdate($timestamp); print_r($info); ?>
This will produce following result −
Array ( [seconds] => 29 [minutes] => 49 [hours] => 10 [mday] => 8 [wday] => 5 [mon] => 5 [year] => 2020 [yday] => 128 [weekday] => Friday [month] => May [0] => 1588934969 )