The mktime() and gmmktime() functions in PHP are used to generate Unix timestamps from specific date and time values. The main difference is that mktime() works with the local timezone, while gmmktime() always uses GMT.
mktime() is timezone-dependent.gmmktime() ignores local timezone settings.
// Syntax for local time timestamp
mktime(hour, minute, second, month, day, year);
// Syntax for GMT based timestamp
gmmktime(hour, minute, second, month, day, year);
// Generate timestamp using local timezone
<?php
echo mktime(12, 0, 0, 12, 31, 2025);
?>
This creates a Unix timestamp for 31 December 2025, 12:00 PM based on the server’s local timezone.
// Generate timestamp using GMT timezone
<?php
echo gmmktime(12, 0, 0, 12, 31, 2025);
?>
This generates a Unix timestamp for the same date and time but strictly using GMT.
gmmktime() for timezone-independent calculations.date() for formatting.