Quick Reach
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:
Experience this example online
1
2
3
4
5
6
7
8
9
|
<?php
// Lets says, its 15 jan 2009 today
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
echo "Tomorrow is ".date("Y/m/d", $tomorrow);
?>
|
Output:
Tomorrow is 2009/01/16
Also read: PHP time | timezone usage | getdate() function | PHP date function and formatting
Leave A Comment?