Skip to content

DateTime and wrong ISO 8601 week numbers #16762

@Nekuin

Description

@Nekuin

Description

The following code:

<?php
        $dates = ["2024-12-28", "2024-12-29", "2024-12-30", "2024-12-31", "2025-01-01"];
        foreach ($dates as $date) {
            $d = new \DateTime($date);
            echo $date . " => " . $d->format("Y-W") . PHP_EOL;
        }

Resulted in this output:

2024-12-28 => 2024-52

2024-12-29 => 2024-52

2024-12-30 => 2024-01

2024-12-31 => 2024-01

2025-01-01 => 2025-01

But I expected this output instead:

2024-12-28 => 2024-52

2024-12-29 => 2024-52

2024-12-30 => 2025-01

2024-12-31 => 2025-01

2025-01-01 => 2025-01

2024-12-30 and 2024-12-31 week numbers seem to be wrong

PHP Version

PHP 8.3.13

Operating System

Ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions