php / php/php-src

DateTime::modify('-1 second') goes 59 minutes later on DST

Open
#21,616 3 comments 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Bug Extension: date Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php
echo (new DateTime('2025-03-30 00:59:59', new DateTimeZone('Europe/London')))
    ->modify('+1 second')
    ->modify('-1 second')
    ->format('Y-m-d H:i:s.u e T');

Resulted in this output:

2025-03-30 02:59:59.000000 Europe/London BST

But I expected this output instead:

2025-03-30 00:59:59.000000 Europe/London GMT

Which is also the output we get when executing (since PHP 8.1, before that add/sub interval and modify gave the same output):

echo (new DateTime('2025-03-30 00:59:59', new DateTimeZone('Europe/London')))
    ->add(new DateInterval('PT1S'))
    ->sub(new DateInterval('PT1S'))
    ->format('Y-m-d H:i:s.u e T');
PHP Version
PHP 8.5.3
Possibly related to

#15880

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.