PHP mktime() Function – Getting a Unix Timestamp

The article explains PHP's mktime() function, detailing its syntax, parameter list, default behavior, return value, and provides a complete example showing how to generate a Unix timestamp for a specific date and time.

Laravel Tech Community
Laravel Tech Community
Laravel Tech Community
PHP mktime() Function – Getting a Unix Timestamp

This page shares a PHP knowledge point: the mktime() function returns a Unix timestamp for a given date and time.

Syntax :

int mktime([int $hour = date("H")], [int $minute = date("i")], [int $second = date("s")], [int $month = date("n")], [int $day = date("j")], [int $year = date("Y")], [int $is_dst = -1])

The function calculates the number of seconds elapsed since the Unix epoch (January 1 1970 00:00:00 GMT). Parameters may be omitted from right to left; omitted values default to the current local date and time.

Parameters :

hour – hour of the day.

minute – minute of the hour.

second – seconds (0‑59).

month – month number.

day – day of the month.

year – two‑ or four‑digit year (0‑69 maps to 2000‑2069, 70‑100 maps to 1970‑2000).

is_dst – 1 if daylight‑saving time is in effect, 0 if not, or -1 (default) if unknown; PHP will try to determine it.

Return value : the Unix timestamp corresponding to the supplied arguments.

Example :

<?php
// Set the default timezone (available since PHP 5.1)
date_default_timezone_set('UTC');

// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date('l', mktime(0, 0, 0, 7, 1, 2000)) . "
";

// Prints something like: 2006-04-05T01:02:03+00:00
echo date('c', mktime(1, 2, 3, 4, 5, 2006));
?>

The article ends with a reminder that following and sharing knowledge is a virtue.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

datetimemktimephp-functionsunix-timestamp
Laravel Tech Community
Written by

Laravel Tech Community

Specializing in Laravel development, we continuously publish fresh content and grow alongside the elegant, stable Laravel framework.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.