Skip to content

Unexpected Results with PHP8 date_diff for Different Timezones #13857

Open
@nnks1010

Description

@nnks1010

Description

In PHP 8.1.25, running date_diff against different time zones returned unexpected results.

https://3v4l.org/RFQMt

The following code:

<?php
date_default_timezone_set('Asia/Tokyo');
$nowDate = (new DateTime('2024-04-01 00:49:22'))->setTimeZone(new DateTimeZone('Asia/Tokyo'));
$endDate = (new DateTime('2024-04-01 08:48:22'))->setTimeZone(new DateTimeZone('UTC'));
echo date_diff($nowDate, $endDate)->format('%Y-%M-%D %H:%I:%S');

Resulted in this output:

-1-11-31 07:59:00

But I expected this output instead:

00-00-00 07:59:00

PHP Version

PHP 8.1.25

Operating System

Ubuntu 22.04

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions