PHP | mktime() Function (original) (raw)

Last Updated : 11 Jul, 2025

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,hour, hour,minute, second,second, second,month, day,day, day,year, $is_dst)

Parameters: This function accepts seven parameters as mentioned above and described below:

Return Value: This function returns an integer Unix timestamp on success and False on error.Exceptions:

Below programs illustrate the mktime() function in PHP:Program 1:

php `

`

Output:

December 1, 2002 was on a Sunday

Program 2:

php `

"; // 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)); ?>

`

Output:

Dec-01-2002
Jan-09-2003

Related Articles:

Reference: https://www.php.net/manual/en/function.mktime.php