Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

mktime

Builds a timestamp from separate parts of a date.

Syntax

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

Parameters

ParameterTypeDescription
$hourintThe hours.
$minute?intThe minutes.
$second?intThe seconds.
$month?intThe month.
$day?intThe day.
$year?intThe year.

Return value

int|falseA timestamp.

Examples

A date from its parts:

<?php
 
echo date('d.m.Y H:i', mktime(14, 5, 0, 1, 30, 2025));

Output:

30.01.2025 14:05

Extra days roll over into the next month:

<?php
 
echo date('d.m.Y', mktime(0, 0, 0, 1, 32, 2025));

Output:

01.02.2025

Notes

The argument order is unusual: the time first, then the month, the day and the year.

See also

  • date — Formats a date and time.
  • time — Returns the current timestamp.
  • checkdate — Checks whether such a date exists.

Related recipes

In the tutorial

  • Date and time — Working with dates in PHP — the date function, the DateTimeImmutable class, formats, adding to dates and the difference between them.

Thanks for reading!

Donate to the site — we work hard for you.