English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP getdate() Function Usage and Examples

PHP Date & Time Function Manual

The getdate() function to obtain date/time information

Definition and Usage

The getdate() function to obtain information about a specific date/Time information. It accepts an optional parameter to specify the timestamp for which you need information. If no parameters are passed, this function returns information about the current local time.

Time information. It accepts an optional parameter to specify the timestamp for which you need information. If no parameters are passed, this function returns information about the current local time.

Syntax

getdate([$timestamp])

ParameterNumber
1Parameter and description

timestamp/Timestamp of the date. This represents the timestamp for which you need information.

Return value

The PHP getdate() function returns an array containing information about the given time/The following are the key units in the returned associative array:

The key unit in the returned associative array
Key nameDescriptionReturn value example
"seconds"The numeric representation of the second0 to 59
"minutes"The numeric representation of the minute0 to 59
"hours"The numeric representation of the hour0 to 23
"mday"The numeric representation of the day of the month1 to 31
"wday"The numeric representation of the day of the week0 (Sunday) to 6 (Saturday)
"mon"The numeric representation of the month1 to 12
"year"4 digit representation of the complete yearfor example: 1999 or 2003
"yday"The numeric representation of the day of the year0 to 365
"weekday"The full text representation of the day of the weekSunday to Saturday
"month"The full text representation of the month, such as January or MarchJanuary to December
0seconds since the Unix epoch to the present day, and time() return values and for date() values are similar.system-related, with a typical value of from -2147483648 to 2147483647.

PHP version

This function was initially introduced in PHP version4introduced and can be used in all higher versions.

Online example

The following examples demonstrategetdate()Usage of the function-

<?php
   $info = getdate();
   print_r($info); 
?>
Test and see‹/›

Output result

Array
(
    [seconds] => 34
    [minutes] => 52
    [hours] => 12
    [mday] => 8
    [wday] => 5
    [mon] => 5
    [year] => 2020
    [yday] => 128
    [weekday] => Friday
    [month] => May
    [0] => 1588942354
)

Online example

Now, let's try to pass the timestamp to this function-

<?php
   $timestamp = time();-(23*12*30);
   $info = getdate($timestamp);
   print_r($info); 
?>
Test and see‹/›

Output result

Array
(
    [seconds] => 29
    [minutes] => 49
    [hours] => 10
    [mday] => 8
    [wday] => 5
    [mon] => 5
    [year] => 2020
    [yday] => 128
    [weekday] => Friday
    [month] => May
    [0] => 1588934969
)