Home >>PHP Date Time Functions >PHP getdate() Function

PHP getdate() Function

PHP getdate() Function

PHP getdate() function is used to get date and time information of the given current local date and time. It accepts one parameter that is the given timestamp. It returns an array with information of the given input timestamp.

Syntax:

  getdate(timestamp);

Parameter Values

Parameter Description
timestamp This is an optional parameter. This parameter defines the integer Unix timestamp.

Here is an example of getdate() function in PHP:

<html>
<body>
<pre>
<?php
print_r(getdate());
?>
</pre>
</body>
</html>
Output:
Array
(
    [seconds] => 52
    [minutes] => 32
    [hours] => 8
    [mday] => 1
    [wday] => 6
    [mon] => 2
    [year] => 2020
    [yday] => 31
    [weekday] => Saturday
    [month] => February
    [0] => 1580545972
)

Example 2:

<html>
<body>
<?php
$date=getdate(date("U"));
echo "$date[mday] $date[month], $date[year] ($date[weekday])";
?>
</body>
</html>
Output:
1 February, 2020 (Saturday)

No Sidebar ads