PHP mktime() Function

What is a mktime Function?


The "mktime()" function is used to get unix timestamp for a date.



In the above syntax the timestamp contains the number of seconds between the Unix Epoch (January 1 1970 00:00:00 GMT) and the time specified. The parameters are hour, minute, second, month, day, year, is_dst is an optional parameter is set to 1 in daylight saving, otherwise it can be 0 or -1.

Example :

echo date("M-d-Y", mktime(0, 0, 0, 12, 28, 2006));
echo date("M-d-Y", mktime(0, 0, 0, 10, 34, 2006));
Result :


In the above example, mktime() returns the Unix timestamp of the arguments given. First the date is printed in the specified format as it has "28" days, the second statement the number of days is 34, no month has 34 days, mktime() by default takes the date as "3" leaving "4", while keeping other parameters as it is.

Note :

(PHP 4, PHP 5)

PHP Topics

Ask Questions

Ask Question