Home » PHP

PHP getdate() function with example

PHP getdate() function: Here, we are going to learn about the PHP getdate() function with its syntax, parameters, returns type, and example.
Submitted by IncludeHelp, on August 13, 2019

PHP getdate() function

getdate() function is used to get the local date/time (or it is also used to get the date/time based on the given timestamp.

Syntax:

    getdate(timestamp);

Parameter(s):

  • timestamp – It is an optional parameter which specifies the timestamp (which is based on an integer UNIX timestamp) – if we do not pass the timestamp the function returns the local date/time.

Timestamps: Following are the timestamps,

  • seconds - it is used to get the time in seconds
  • minutes - it is used to get the time in minutes
  • hours - it is used to get the time in hours
  • mday - it is used to get the day of the month
  • wday - it is used to get the day of the week
  • mon - it is used to get the month
  • year - it is used to get the year
  • yday - it is used to get the day of the year
  • weekday - it is used to get the name of the week
  • month - it is used to get the name of the month
  • 0 - it is used to get the seconds since Unix Epoch

Return value:

It returns an array of the date/time information with the timestamp

Example: PHP code to demonstrate the example of getdate() function

<?php
//getting the complete date/time 
//i.e. local date/time
$result = getdate();
echo "getdate() result...\n";
print_r($result);

//extracting the indivisual values 
//based on the timestamps
echo "seconds:  $result[seconds]\n";
echo "minutes:  $result[minutes]\n";
echo "hours:    $result[hours]\n";
echo "mday:     $result[mday]\n";
echo "wday:     $result[wday]\n";
echo "mon:      $result[mon]\n";
echo "year:     $result[year]\n";
echo "yday:     $result[yday]\n";
echo "weekday:  $result[weekday]\n";
echo "month:    $result[month]\n";
echo "0:        $result[0]\n";
?>

Output

getdate() result...
Array
(
    [seconds] => 28
    [minutes] => 56
    [hours] => 12
    [mday] => 13
    [wday] => 2
    [mon] => 8
    [year] => 2019
    [yday] => 224
    [weekday] => Tuesday
    [month] => August
    [0] => 1565700988
)
seconds:  28
minutes:  56
hours:    12
mday:     13
wday:     2
mon:      8
year:     2019
yday:     224
weekday:  Tuesday
month:    August
0:        1565700988

Reference: PHP getdate() function







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.