mktime
Get Unix timestamp for a date.
mktime Function synopsis
mktime(
int $hour,
?int $minute = null,
?int $second = null,
?int $month = null,
?int $day = null,
?int $year = null
): int|false
Parameters
$hour
Typeint
The number of the hour relative to the start of the day determined by
$month, $day and $year.
Negative values reference the hour before midnight of the day in question.
Values greater than 23 reference the appropriate hour in the following day(s).
$minute
OptionalType?intDefault valuenull
The number of the minute relative to the start of the $hour.
Negative values reference the minute in the previous hour.
Values greater than 59 reference the appropriate minute in the following hour(s).
$second
OptionalType?intDefault valuenull
The number of seconds relative to the start of the $minute.
Negative values reference the second in the previous minute.
Values greater than 59 reference the appropriate second in the following minute(s).
$month
OptionalType?intDefault valuenull
The number of the month relative to the end of the previous year. Values 1 to 12 reference the normal calendar months of the year in question. Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc. Values greater than 12 reference the appropriate month in the following year(s).
$day
OptionalType?intDefault valuenull
The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).
$year
OptionalType?intDefault valuenull
The number of the year, may be a two or four digit value,
with values between 0-69 mapping to 2000-2069 and 70-100 to
1970-2000. On systems where time_t is a 32bit signed integer, as
most common today, the valid range for $year
is somewhere between 1901 and 2038.
Return value
Typeint|false
mktime returns the Unix timestamp of the arguments
given, or false if the timestamp doesn't fit in a PHP integer.
Changes to the mktime Function
PHP 8.0
- Return type added:
int|false - Parameter type added for parameter #1 (
$hour):int - Parameter name of parameter #2 changed:
$minto$minute - Parameter type added for parameter #2 (
$minute):?int - Parameter default value added for position #2 (
$minute):null - Parameter name of parameter #3 changed:
$secto$second - Parameter type added for parameter #3 (
$second):?int - Parameter default value added for position #3 (
$second):null - Parameter name of parameter #4 changed:
$monto$month - Parameter type added for parameter #4 (
$month):?int - Parameter default value added for position #4 (
$month):null - Parameter type added for parameter #5 (
$day):?int - Parameter default value added for position #5 (
$day):null - Parameter type added for parameter #6 (
$year):?int - Parameter default value added for position #6 (
$year):null
mktime(
- $hour,
+ int $hour,
- $min,
+ ?int $minute = null,
- $sec,
+ ?int $second = null,
- $mon,
+ ?int $month = null,
- $day,
+ ?int $day = null,
- $year
+ ?int $year = null
- )
+ ): int|false PHP 7.0
- Parameter count changed:
7to6 - Optional parameter removed - #7:
$is_dst
mktime(
$hour,
$min,
$sec,
$mon,
$day,
- $year,
- $is_dst
+ $year
) PHP 5.5
- Optional parameter added - #7:
$is_dst
mktime(
$hour,
$min,
$sec,
$mon,
$day,
- $year
+ $year,
+ $is_dst
) mktime Function Availability
mktime Function Availability| PHP Version | Availability |
|---|---|
| PHP 8.6Upcoming Release | Yes |
| PHP 8.5Supported (Latest) | Yes |
| PHP 8.4Supported | Yes |
| PHP 8.3Security-Fixes Only | Yes |
| PHP 8.2Security-Fixes Only | Yes |
| PHP 8.1Unsupported | Yes |
| PHP 8.0Unsupported | Yes |
| PHP 7.4Unsupported | Yes |
| PHP 7.3Unsupported | Yes |
| PHP 7.2Unsupported | Yes |
| PHP 7.1Unsupported | Yes |
| PHP 7.0Unsupported | Yes |
| PHP 5.6Unsupported | Yes |
| PHP 5.5Unsupported | Yes |
| PHP 5.4Unsupported | Yes |
| PHP 5.3Unsupported | Yes |