PHP mktime() Function

Quick summary: The PHP mktime() function creates a Unix timestamp from date components.

PHP mktime() Syntax

mktime(int $hour, ?int $minute = null, ?int $second = null, ?int $month = null, ?int $day = null, ?int $year = null): int|false
PHP

PHP mktime() Basic examples

var_dump(mktime(12, 0, 0, 2, 8, 2026));
PHP
Output:
int(1765252800)

Creates a timestamp for a specific date and time.

PHP mktime() Real-world usage

$expires = mktime(0, 0, 0, 12, 31, 2026);
echo date('Y-m-d', $expires);
PHP
Output:
2026-12-31

Generates fixed expiration dates.

PHP mktime() Edge cases

var_dump(mktime(0,0,0,13,1,2026));
PHP
Output:
int(...)

Month overflow is automatically normalized.

PHP mktime() Common mistakes

Using mktime with user input

Invalid input can cause unexpected normalization.

Incorrect
mktime(0,0,0,$_GET['m'],1,2026);
Correct
strtotime($_GET['date']);

Use strtotime for flexible user input.

PHP mktime() Frequently Asked Questions

What does mktime() do?

Creates a Unix timestamp from date components.

Use case?

Manual timestamp creation.

Parameters?

hour, minute, second, month, day, year.

Handles overflow?

Yes.

Common mistake?

Wrong parameter order.

Timezone dependent?

Yes.

Performance?

Fast.

Alternative?

strtotime().

Returns int?

Yes.

Safe?

Yes.

Used with date()?

Yes.

Best practice?

Prefer DateTime.

PHP mktime() Related PHP Functions