Current Location: Home> Latest Articles> PHP gmmktime() Function Explained: Usage, Parameters, and Examples

PHP gmmktime() Function Explained: Usage, Parameters, and Examples

M66 2025-10-22

Introduction to PHP gmmktime() Function

The gmmktime() function in PHP returns a Unix timestamp for a date based on GMT (Greenwich Mean Time). It works similarly to the mktime() function but differs in that gmmktime() always uses GMT, unaffected by the local timezone.

Syntax

gmmktime(hour, minute, second, month, day, year, is_dst);

Parameter Description

  • hour: Specifies the hour.

  • minute: Specifies the minute.

  • second: Specifies the second.

  • month: Specifies the month.

  • day: Specifies the day.

  • year: Specifies the year.

  • is_dst: Indicates whether daylight saving time is in effect. Since gmmktime() works with GMT, this parameter has no effect on the result.

Return Value

This function returns an integer Unix timestamp that represents the number of seconds since January 1, 1970, 00:00:00 GMT.

Example 1

Here’s a basic example:

<?php
   $time = gmmktime(0, 0, 0, 9, 10, 2017);
   print($time . "\n");
?>

Output

1505001600

Example 2

This example shows how to combine gmmktime() with the date() function:

<?php
   echo "Nov 10, 2017 was on a " . date("l", gmmktime(0, 0, 0, 11, 10, 2017));
?>

Output

Nov 10, 2017 was on a Friday

Conclusion

The gmmktime() function is very useful when dealing with time calculations that should remain independent of time zones. It is often used for internationalized applications, log recording, or any scenario requiring GMT-based time comparisons. Understanding how to use gmmktime() helps developers manage and convert time data more effectively.