How to use PHP mktime function with date function

What is PHP mktime() function?

The mktime function is used to get the timestamps for a specified date.

See an example of mktime function

In order to get a timestamp for a specific date rather using the current date/time, the PHP provides mktime() function. The specified date can be future or past.

How to use the mktime function

Following is the general syntax of using the mktime PHP function:

mktime ( hour, minute, second, month, day, year, is_dst)

Each of the parameters is explained below:

  • Hour – in the numeric value.
  • Minute – in the numeric value.
  • Second – Number of seconds past the minute.
  • Month – Number of the month.
  • Day – Number of the day.
  • Year – Two or four digit representation of the year.
  • Is_dst – Represents daylight savings time, 1=yes, 0=no, and -1= default/unknown.

Example of using mktime()

Let us add one day to the current date by using the PHP mktime() in the example below:

PHP mktime

Experience this example online


Tomorrow is 2009/01/16


Also read: PHP time | timezone usage | getdate() function | PHP date function and formatting

Was this article helpful?

Related Articles

Leave A Comment?