PHP getdate() function

PHP getdate() function

The PHP getdate() function is used to returns date time. The getdate() function return an array with all the date and time values.

The PHP getdate() function syntax:

getdate( timestamp);

The time stamp is optional. without time stamp the function will return current local date and time values. We use getdate() function for comparison between two dates.

Example of PHP getdate() function

Here, are the lists of elements contained in array returned by getdate() function in php.

  • mday – for day of the month (1 – 31)
  • wday – for dat of the week (1 – 6)
  • yday – for day of the year (0 – 365)
  • mon – for month of year in digit (1 – 12)
  • month – for month of year in string (January)
  • year – for year in four digit (2015)
  • hours – for display hours of day (0 – 23)
  • minutes – for display minutes of hour (0 – 59)
  • seconds – for display seconds of minutes (0 – 59
  • weekday – for day of the week (Monday)
  • 0 – for timestamp

Example of PHP getdate() function

The output of getdate() function example :

The Day of month = 20
Day of week = 6
Day of year = 232
Month of year in digit = 8
Month of year = August
Year is = 2016
Hours is = 6
Minutes is = 59
Seconds is = 10
Day of week is = Saturday
Timestamp is = 1471669150


getdate() function example :

Now, lets an example to calculate difference between two dates using getdate() function.
Here, we assume some value for day in digit and get current day of year value from getdate() function then subtracts day value from current day of year value, you will get difference of two dates in result.

The output is :

The Result is = 182

Leave a Reply

Your email address will not be published. Required fields are marked *

3 + 2 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">