What is PHP gmdate() Function?
If you want to format a specific time to a human readable format according to GMT or UTC, use PHP date() function. An example could be Jan 08 2026 17:25:00 UTC.
In practice, GMT (Greenwich Mean Time) and UTC (Coordinated Universal Time or Universal Time Coordinated) indicate same time. In 1972, the UTC replaced GMT.
The function actually takes a timestamp and converts it to your desirable date and time format according to GMT or UTC. Now, you may ask what the timestamp is.
Timestamp: Timestamp of a specific time is the number of second from1st January 1970 00:00:00 Greenwich Mean Time (GMT) to that specific time. 1st January 1970 00:00:00 Greenwich Mean Time (GMT) is known as Unix Epoch.
So, from a timestamp (which is just a number of some seconds) we human can’t read a date. We need to convert this seconds to a date and time format. And PHP date() function helps us to accomplish this.
Syntax:
gmdate(format, timestamp)
Parameters:
The Function has 1 required parameter and 1 optional parameter-
format (required): This is a string. It is the format how you want the date to be displayed.
The PHP gmdate() function uses some English alphabet letters to construct different parts of a date and time. When using in the “format” parameter, they carry special meaning. Check the “Formatting letters/ Characters” table below for the full character list with their meaning and examples. Check example 1 to see the formatting characters in action.
timestamp (optional): This is an integer which is an UNIX timestamp. It could indicate any time in the past or in the future. Check example 2. By default, the function uses current date and time as timestamp. That means, if you don’t mention this parameter, the function uses the local time as the timestamp. You can get the current local timestamp from time() function. Check example 3.
Table: Formatting Letters / Characters
| Character | Meaning | Examples | |
|---|---|---|---|
| Day | d | 2 digits day of the months with leading zero. | 01, 02, ….31 |
| D | 3 letters abbreviated day name of the week. | Sun, Mon, …Sat | |
| j | Day of the months without leading zero. | 1, 2, …..31 | |
| l (lowercase “L”) | Full day name of the week. | Sunday, …Saturday | |
| N | ISO 8601 numeric day of the week where 1 indicates to Monday while 7 to Sunday. | 1 (for Monday), 5 (Friday), … | |
| S (capital) | 2 characters English ordinal suffix for the day of the month. It fits well after day of the month like 1st , 3rd etc. | st, nd, rd, th, …. | |
| w (lowercase) | Numeric day of the week where 0 indicates Sunday and 6 indicates Saturday | 0 (for Sunday), 5 (Friday), … | |
| z (lowercase) | Day of the year without leading zero. | 1, 2, 3, … 365 | |
| Week | W | ISO 8601 week number of the year. A week starts on Monday. First week of a year starts on first Monday of the January. The character “W” indicates in which week a timestamp is in. | 52 (52th week of the year) |
| Month | F | Full name of the month. | January, February, … |
| m | 2 digits month of the year with leading zero. | 01 (for January), 02, ….12 (for December) | |
| M | 3 letters abbreviated month of the year. | Jan, Feb, …Dec | |
| n | Name of the month without leading zero. | 1,2,…..12 | |
| t | Number of days of a month. | It could be 28 to 31 | |
| Year | L | Whether it is leap year or not. | 1 (for leap year), 0 (for not leap year) |
| o (lowercase) | ISO 8601 year number based on week-number. Same as Y except if the ISO week number is part of the previous or next year, it will display that year. It may happen in the beginning or in the end of the year, | 2024, 1990, etc. | |
| X | An at least 4 digits of a year. In front of the year – is added if it is BCE and + if it is CE. | -0004, +0579, … | |
| x (lowercase) | An at least 4 digits of a year. In front of the year – is added if it is BCE and + if it is 10000 or beyond. | -1000, 0900, +10001 | |
| Y | A 4 digits year. | 2024, 1999, 0109 etc. | |
| y (lowercase) | A 2 digit year. | 24, 99, 09 | |
| Time | a | Lowercase Ante-meridiem and Post-meridiem. | am, pm |
| A | Uppercase Ante-meridiem and Post-meridiem. | AM, PM | |
| B | Swatch internet time. The character “B” the Swatch internet time of the provided timestamp. | 000, 001, … 999 | |
| g | 12 hours format of an hour without leading zeros. | 1 to 12 | |
| G | 24 hours format of an hour without leading zeros. | 0 to 23 | |
| h | 12 hours format of an hour with leading zeros. | 01 to 12 | |
| H | 24 hours format of an hour with leading zeros. | 00 to 23 | |
| i | Minutes with leading zeros. | 00 to 59 | |
| s (lowercase) | Seconds with leading zeros. | 00 to 59 | |
| u (lowercase) | Microseconds. 1,000,000 of a second. | 100,000, 999,999 | |
| v (lowercase) | Milliseconds. 1,000 of a second. | 123, 999 | |
| Timezone | e | Timezone. | GMT, UTC… |
| I (capital) | Whether it is in daylight saving time or not. 1 if it is in daylight saving time 0 otherwise. | 1 or 0. | |
| O (capital) | Time difference from the specific time to the GMT without color between hours and minutes | +0100, -800 etc. | |
| P (capital) | Time difference from the specific time to the GMT with color between hours and minutes. | -08:00 etc. | |
| p (lowercase) | Time difference from the specific time to the GMT with color between hours and minutes. It shows z instead of +0:00 for UTC time. | Z, +01:00 etc. | |
| T | Timezone abbreviation. | HKT, MSK etc. | |
| Z (capital) | Timezone offset (difference in hours and minutes between a timestamp’s timezone and UTC). For timezones that are west of UTC are negative and for timezones that are east of UTC are positive. | -43200 through 50400 | |
| Full Date/Time | c | The ISO 8601 date | 2023-12-27T11:44:39+00:00 |
| r | The RFC 2822/ RFC 5322 formatted date | Wed, 27 Dec 2023 11:44:39 +0000 | |
| U (capital) | The seconds since UNIX Epoch (January 1 1970 00:00:00 GMT) | 1703677738 |
Return Values:
It returns the formatted date of the timestamp –
- specified in the second parameter, or
- of the current date and time if the second parameter is not specified.
Examples:
Example 1:
<?php
echo "Current UTC/GMT time is: " . gmdate("d F Y g:i A");
echo "<br />";
echo "According to UTC/GMT, we're in the week: ".date("W");
?>
Output:
Current UTC/GMT time is: 10 January 2026 4:29 AM
According to UTC/GMT, we’re in the week: 02
Example 2:
<?php
echo "Current UTC/GMT time is: " . gmdate("d F Y g:i A", time());
?>
Output:
Current UTC/GMT time is: 10 January 2026 4:29 AM
Exercise 3:
<?php
date_default_timezone_set("America/Los_Angeles");
echo "Local Los Angeles time is: " . date("H:i A");
echo "<br />";
echo "Local UTC/GMT time is: " . gmdate("H:iA ");
?>
Output:
Local Los Angeles time is: 20:29 PM
Local UTC/GMT time is: 04:29AM
Exercise 4:
<?php
echo "After 1 week, UTC/GMT time will be: " . gmdate("d F Y g:i A", strtotime("+1 week"));
?>
Output:
After 1 week, UTC/GMT time will be: 17 January 2026 4:29 AM
Notes on gmdate() Function:
- gmdate() function is identical to date() function except the UTC/GMT timezone part.
PHP Version Support:
PHP 4, PHP 5, PHP 7, PHP 8
Summary: PHP gmdate() Function
The gmdate() function may be the most commonly used built-in PHP date and time function. Use this function when you need UTC/GMT date and time.