gmmktime

Get Unix timestamp for a GMT date

Syntax

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

Parameters

hour

The number of the hour relative to the start of the day determined by month, day and year. Negative values reference the hour before midnight of the day in question. Values greater than 23 reference the appropriate hour in the following day(s).

minute

The number of the minute relative to the start of the hour. Negative values reference the minute in the previous hour. Values greater than 59 reference the appropriate minute in the following hour(s).

second

The number of seconds relative to the start of the minute. Negative values reference the second in the previous minute. Values greater than 59 reference the appropriate second in the following minute(s).

month

The number of the month relative to the end of the previous year. Values 1 to 12 reference the normal calendar months of the year in question. Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc. Values greater than 12 reference the appropriate month in the following year(s).

day

The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s).

year

The year

Return

Returns a int Unix timestamp on success, or false on failure.

Examples

1 · return

<?

date_default_timezone_set("America/Los_Angeles");

$hour = 4;

$return = gmmktime($hour);

echo $return;

?>
1675570941

2 · hour

<?

date_default_timezone_set("America/Los_Angeles");

$hour = 4;

$return = gmmktime($hour);

echo date("Y-m-d H:i:s", $return);

?>
2023-02-04 20:22:21

3 · minute

<?

date_default_timezone_set("America/Los_Angeles");

$hour = 4;
$minute = 5;

$return = gmmktime($hour, $minute);

echo date("Y-m-d H:i:s", $return);

?>
2023-02-04 20:05:21

4 · second

<?

date_default_timezone_set("America/Los_Angeles");

$hour = 4;
$minute = 5;
$second = 6;

$return = gmmktime($hour, $minute, $second);

echo date("Y-m-d H:i:s", $return);

?>
2023-02-04 20:05:06

5 · month

<?

date_default_timezone_set("America/Los_Angeles");

$hour = 4;
$minute = 5;
$second = 6;
$month = 2;

$return = gmmktime($hour, $minute, $second, $month);

echo date("Y-m-d H:i:s", $return);

?>
2023-02-04 20:05:06

6 · day

<?

date_default_timezone_set("America/Los_Angeles");

$hour = 4;
$minute = 5;
$second = 6;
$month = 2;
$day = 3;

$return = gmmktime($hour, $minute, $second, $month, $day);

echo date("Y-m-d H:i:s", $return);

?>
2023-02-02 20:05:06

7 · year

<?

date_default_timezone_set("America/Los_Angeles");

$hour = 4;
$minute = 5;
$second = 6;
$month = 2;
$day = 3;
$year = 2001;

$return = gmmktime($hour, $minute, $second, $month, $day, $year);

echo date("Y-m-d H:i:s", $return);

?>
2001-02-02 20:05:06

8 · Previous

<?

date_default_timezone_set("America/Los_Angeles");

$hour = date("H") - 1;
$minute = date("i") - 1;
$second = date("s") - 1;
$month = date("m") - 1;
$day = date("d") - 1;
$year = date("Y") - 1;

$return = gmmktime($hour, $minute, $second, $month, $day, $year);

echo date("Y-m-d H:i:s", $return);

?>
2022-01-03 11:21:20

9 · Next

<?

date_default_timezone_set("America/Los_Angeles");

$hour = date("H") + 1;
$minute = date("i") + 1;
$second = date("s") + 1;
$month = date("m") + 1;
$day = date("d") + 1;
$year = date("Y") + 1;

$return = gmmktime($hour, $minute, $second, $month, $day, $year);

echo date("Y-m-d H:i:s", $return);

?>
2024-03-05 13:23:22

10 · Lesser

<?

date_default_timezone_set("America/Los_Angeles");

echo date("Y-m-d", gmmktime(0, 0, 0, 2, 29, 2000)) . PHP_EOL;
echo date("Y-m-d", gmmktime(0, 0, 0, 3, 0, 2000)) . PHP_EOL;
echo date("Y-m-d", gmmktime(0, 0, 0, 4, -31, 2000));

?>
2000-02-28
2000-02-28
2000-02-28

11 · Greater

<?

date_default_timezone_set("America/Los_Angeles");

echo date("Y-m-d", gmmktime(0, 0, 0, 1, 1, 2001)) . PHP_EOL;
echo date("Y-m-d", gmmktime(0, 0, 0, 12, 32, 2000)) . PHP_EOL;
echo date("Y-m-d", gmmktime(0, 0, 0, 13, 1, 2000));

?>
2000-12-31
2000-12-31
2000-12-31

checkdate

date

date_add

date_create

date_create_from_format

date_create_immutable

date_create_immutable_from_format

date_date_set

date_default_timezone_get

date_default_timezone_set

date_diff

date_format

date_get_last_errors

date_interval_create_from_date_string

date_interval_format

date_isodate_set

date_modify

date_offset_get

date_parse

date_parse_from_format

date_sub

date_sun_info

date_sunrise

date_sunset

date_time_set

date_timestamp_get

date_timestamp_set

date_timezone_get

date_timezone_set

getdate

gettimeofday

gmdate

gmstrftime

idate

localtime

microtime

mktime

strftime

strptime

strtotime

time

timezone_abbreviations_list

timezone_identifiers_list

timezone_location_get

timezone_name_from_abbr

timezone_name_get

timezone_offset_get

timezone_open

timezone_transitions_get

timezone_version_get

PHP

Home Menu