PHP | mktime() Function
The mktime() function is an inbuilt function in PHP which is used to return the Unix timestamp for a date. The timestamp returns a long integer containing the number of seconds between the Unix Epoch (January 1, 1970, 00:00:00 GMT) and the time specified. The hour, minute, second, month, day and year are sent as parameters to the mktime() function and it returns an integer Unix timestamp on success and False on error.
Syntax:
int mktime( $hour, $minute, $second, $month, $day, $year, $is_dst)
Parameters: This function accepts seven parameters as mentioned above and described below:
- $hour: It is an optional parameter which specifies the hour.
- $minute: It is an optional parameter which specifies the minute.
- $second: It is an optional parameter which specifies the second.
- $month: It is an optional parameter which specifies the month.
- $day: It is an optional parameter which specifies the day.
- $year: It is an optional parameter which specifies the year.
- $is_dst: It is an optional parameter which can be set to 1 if the time is during daylight savings time (DST), or 0 if it is not.
Return Value: This function returns an integer Unix timestamp on success and False on error.
Exceptions:
- PHP 5.3.0 version throws an E_DEPRECATED error if the is_dst parameter is used.
- The mktime() function throws a E_NOTICE on every call to a date/time if the time zone is not valid.
Below programs illustrate the mktime() function in PHP:
Program 1:
<?php // Using mktime() function to know the day echo "December 1, 2002 was on a " . date("l", mktime(0, 0, 0, 12, 1, 2002)); ?> |
December 1, 2002 was on a Sunday
Program 2:
<?php // Using mktime() function to know the complete date echo date("M-d-Y", mktime(0, 0, 0, 12, 1, 2002)) . "<br>"; // Using mktime() function to know the // complete date for an out-of-range input echo date("M-d-Y", mktime(0, 0, 0, 12, 40, 2002)); ?> |
Dec-01-2002
Jan-09-2003
Related Articles:
Reference: http://php.net/manual/en/function.mktime.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name inside a function in PHP ?
- How to get the function name from within that function using JavaScript ?
- PHP | min( ) Function
- p5.js | box() Function
- PHP | Ds\Set add() Function
- PHP | max( ) Function
- D3.js | d3.min() function
- D3.js | d3.map.set() Function
- CSS | rgb() Function
- PHP | Ds\Map get() Function
- p5.js | str() function
- PHP | dir() Function
- D3.js | d3.lab() Function
- p5.js | value() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



