PHP date_offset_get() Function

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

Definition

In PHP, date_offset_get() returns the timezone offset of a date object in seconds, including daylight saving time when it applies.

It is the procedural name for DateTime::getOffset() and DateTimeImmutable::getOffset(). Positive numbers are east of UTC and negative numbers are west of UTC.

Syntax

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

PHP
$seconds = date_offset_get($date);
CallWhat it does
date_offset_get($kolkata)Returns 19800, which is 5 hours 30 minutes ahead of UTC.
date_offset_get($newYorkJanuary)Returns -18000, which is 5 hours behind UTC (standard time).
date_offset_get($newYorkJuly)Returns -14400, which is 4 hours behind UTC (daylight saving time).

The offset belongs to the date you ask about, so the same timezone can give different numbers in winter and summer. Divide by 3600 to get hours. Modern code usually calls $date->getOffset() on a DateTimeImmutable.

Library declarations
PHP
date_offset_get(DateTimeInterface $object): int

Parameters

ParameterDescription
objectRequired. A DateTime or DateTimeImmutable object.

Return Value

Return ValueDescription
intThe offset from UTC in seconds. It is negative for timezones west of UTC.

PHP Examples

Example 1 — Offsets in Different Timezones

Create dates in two timezones and compare their offsets in seconds.

PHP
<?php
$kolkata = date_create("2024-01-15 12:00:00", timezone_open("Asia/Kolkata"));
$winter = date_create("2024-01-15 12:00:00", timezone_open("America/New_York"));
$summer = date_create("2024-07-15 12:00:00", timezone_open("America/New_York"));

echo date_offset_get($kolkata), PHP_EOL;
echo date_offset_get($winter), PHP_EOL;
echo date_offset_get($summer), PHP_EOL;

How It Works

  1. timezone_open() creates a timezone, and date_create() uses it for each date.
  2. India is 5. 5 hours ahead of UTC, so the offset is +19800 seconds.
  3. New York in January is 5 hours behind UTC, which is -18000 seconds.
  4. In July New York uses daylight saving time, so the offset is -14400 seconds.

Example 2 — UTC and Fixed Offsets

A date can also carry a fixed offset instead of a named timezone.

PHP
<?php
$utc = date_create("2024-06-01 00:00:00", timezone_open("UTC"));
$fixed = date_create("2024-06-01 00:00:00-03:30");

echo date_offset_get($utc), PHP_EOL;
echo date_offset_get($fixed), PHP_EOL;
echo date_offset_get($fixed) / 3600, PHP_EOL;

How It Works

  1. UTC is the reference timezone, so its offset is 0.
  2. The text -03:30 sets a fixed offset of 3 hours 30 minutes behind UTC.
  3. That equals -12600 seconds.
  4. Dividing by 3600 turns seconds into hours, which gives -3. 5.

Example 3 — Format the Offset as Text

Turn the offset in seconds into a label like UTC+05:30.

PHP
<?php
$date = date_create("2024-01-15 12:00:00", timezone_open("Asia/Kolkata"));

$seconds = date_offset_get($date);
$sign = $seconds < 0 ? "-" : "+";
$abs = abs($seconds);
$hours = intdiv($abs, 3600);
$minutes = intdiv($abs % 3600, 60);

echo sprintf("UTC%s%02d:%02d", $sign, $hours, $minutes), PHP_EOL;

How It Works

  1. Read the offset in seconds, which is 19800 for Asia/Kolkata.
  2. Pick a plus or minus sign, then use abs() so the math works with a positive number.
  3. intdiv() gives whole hours (5), and the remainder divided by 60 gives minutes (30).
  4. sprintf() pads the hours and minutes to two digits and builds the label.

Frequently Asked Questions

It returns the difference between the date's timezone and UTC in seconds. For example, India Standard Time gives 19800 and US Eastern Standard Time gives -18000.
Yes. The offset is calculated for the exact date and time of the object, so it changes when daylight saving time is active.
Divide the result by 3600. For example, 19800 / 3600 is 5.5 hours.
Negative offsets mean the timezone is behind UTC, such as the Americas. Positive offsets mean the timezone is ahead of UTC, such as Asia and Europe.
Yes. It is the procedural alias of getOffset() and works with both DateTime and DateTimeImmutable objects.

Next: date_parse()

date_parse() reads a date and time string and returns its parts (year, month, day, hour, m.

date_parse() 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