PHP gmdate() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Date/Time

Definition

In PHP, gmdate() formats a Unix timestamp as a date and time string in Greenwich Mean Time (GMT/UTC).

It works just like date(), but it ignores the default time zone. That makes gmdate() a good choice when you need the same result on every server, such as in logs, APIs and HTTP headers.

Syntax

Call gmdate() with the values you need. Start with this line.

PHP
$text = gmdate('Y-m-d H:i:s', 1700000000);
CallWhat it does
gmdate('Y-m-d H:i:s', 1700000000)Returns "2023-11-14 22:13:20".
gmdate('l', 1700000000)Returns "Tuesday".
gmdate('Y-m-d', 0)Returns "1970-01-01", the Unix epoch date.

gmdate() uses the same format letters as date(): Y for year, m for month, d for day, H for hour, i for minutes and s for seconds. The only difference is that the output is always in UTC.

Library declarations
PHP
gmdate(string $format, ?int $timestamp = null): string

Parameters

ParameterDescription
formatRequired. The format string, made of date format letters such as Y, m, d, H, i, s, D, l, F and M.
timestampOptional. A Unix timestamp. If it is null or left out, the current time is used.

Return Value

Return ValueDescription
stringThe formatted date and time in GMT/UTC.

PHP Examples

Example 1 — Format a Timestamp in UTC

Turn a fixed timestamp into readable strings.

PHP
<?php
$ts = 1700000000;

echo gmdate('Y-m-d H:i:s', $ts), PHP_EOL;
echo gmdate('l, d F Y', $ts), PHP_EOL;
echo gmdate('D, d M Y H:i:s', $ts) . ' GMT', PHP_EOL;

How It Works

  1. The first format prints the common database style, year-month-day then time.
  2. l is the full weekday name and F is the full month name.
  3. D and M are the short weekday and month names, used in HTTP date headers.
  4. ' GMT' is added with the dot operator because the result is always UTC.

Example 2 — The Epoch and Negative Timestamps

Timestamp 0 is the start of 1970. Negative timestamps go back before it.

PHP
<?php
echo gmdate('Y-m-d H:i:s', 0), PHP_EOL;
echo gmdate('Y-m-d H:i:s', -86400), PHP_EOL;
echo gmdate('Y-m-d H:i:s', 86399), PHP_EOL;

How It Works

  1. Timestamp 0 is exactly midnight on 1 January 1970 UTC.
  2. -86400 is one day (86,400 seconds) before the epoch.
  3. 86399 is the very last second of the first day.
  4. gmdate() handles all three without any time zone surprises.

Example 3 — gmdate() vs date() with a Time Zone

date() follows the default time zone, but gmdate() always stays in UTC.

PHP
<?php
date_default_timezone_set('Asia/Kolkata');

$ts = 1700000000;

echo 'UTC:     ', gmdate('Y-m-d H:i', $ts), PHP_EOL;
echo 'Kolkata: ', date('Y-m-d H:i', $ts), PHP_EOL;

How It Works

  1. We set the default time zone to Asia/Kolkata (UTC+5:30).
  2. gmdate() ignores that setting and prints 22:13 on 14 November.
  3. date() adds 5 hours 30 minutes, so it prints 03:43 on 15 November.
  4. Notice that the calendar date is different too, not only the hour.

Frequently Asked Questions

date() uses the default time zone, while gmdate() always uses GMT/UTC. The format letters are the same.
Use it for logs, APIs, caching headers and database values where every server should produce the same text no matter its time zone.
Use gmdate('c', $timestamp). It returns a value like 2023-11-14T22:13:20+00:00.
No. It only formats the timestamp in UTC for that one call. The default time zone stays the same.
It formats the current time in UTC, like gmdate($format, time()).

Next: gmmktime()

gmmktime() builds a Unix timestamp from a date and time that you give in GMT (UTC).

gmmktime() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful