(PHP 4, PHP 5)

getdateGet date/time information


array getdate ([ int $timestamp = time() ] )

Returns an associative array containing the date information of the timestamp, or the current local time if no timestamp is given.



The optional timestamp parameter is an integer Unix timestamp that defaults to the current local time if a timestamp is not given. In other words, it defaults to the value of time().

Return Values

Returns an associative array of information related to the timestamp. Elements from the returned associative array are as follows:

Key elements of the returned associative array
Key Description Example returned values
"seconds" Numeric representation of seconds 0 to 59
"minutes" Numeric representation of minutes 0 to 59
"hours" Numeric representation of hours 0 to 23
"mday" Numeric representation of the day of the month 1 to 31
"wday" Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)
"mon" Numeric representation of a month 1 through 12
"year" A full numeric representation of a year, 4 digits Examples: 1999 or 2003
"yday" Numeric representation of the day of the year 0 through 365
"weekday" A full textual representation of the day of the week Sunday through Saturday
"month" A full textual representation of a month, such as January or March January through December
0 Seconds since the Unix Epoch, similar to the values returned by time() and used by date(). System Dependent, typically -2147483648 through 2147483647.


Example #1 getdate() example


The above example will output something similar to:

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

See Also

  • date() - Format a local time/date
  • idate() - Format a local time/date as integer
  • localtime() - Get the local time
  • time() - بازگرداندن Unix timestamp فعلی
  • setlocale() - Set locale information

add a note add a note

User Contributed Notes 4 notes

Yura Pylypenko (plyrvt at mail dot ru)
10 years ago
In addition to canby23 at ms19 post:
It's a very bad idea to consider day having 24 hours (86400 secs), because some days have 23, some - 25 hours due to daylight saving changes. Using of mkdate() and strtotime() is always preferred. strtotime() also has a very nice behaviour of datetime manipulations:
echo strtotime ("+1 day"), "\n";
strtotime ("+1 week"), "\n";
strtotime ("+1 week 2 days 4 hours 2 seconds"), "\n";
strtotime ("next Thursday"), "\n";
strtotime ("last Monday"), "\n";
andre at anlex dot co dot za
7 years ago
I thought best to show a posseble way to go about bypassing the end month issue where the first day in a new month will have the monday of the week that it falls in - in the old month. Use the numbering of days as the constant and work you way from there.

$now = time();
$num = date("w");
if (
$num == 0)
$sub = 6; }
else {
$sub = ($num-1); }
$WeekMon  = mktime(0, 0, 0, date("m", $now)  , date("d", $now)-$sub, date("Y", $now));    //monday week begin calculation
$todayh = getdate($WeekMon); //monday week begin reconvert

$d = $todayh[mday];
$m = $todayh[mon];
$y = $todayh[year];
"$d-$m-$y"; //getdate converted day


Allot less code makes everyone happy..
timforte at gmail dot com
6 years ago
It's worth noting that this is local time, not UTC/GMT - gmgetdate doesn't exist :(.

The most logical way to handle date arithmetic without hitting DST problems is to work in UTC...

function add_days($my_date,$numdays) {
$date_t = strtotime($my_date.' UTC');
gmdate('Y-m-d',$date_t + ($numdays*86400));

[it's even faster if you use gmmktime instead of strtotime]
eric dot schultz at NOSPAM dot CyVon dot com
5 years ago
Here is another gmgetdate that is a little faster/suscint (no loops).

function gmgetdate2($ts = null){
$k = array('seconds','minutes','hours','mday',

It also returns the values in the same order as getdate.
To Top