Skip to content

Date parser doesn't speak ISO weekdates #20406

@hgshoggins

Description

@hgshoggins

Description

The following code:

<?php
$dateTimeObj_monday = new DateTimeImmutable('2022W1', new DateTimeZone('Europe/Paris'));

Resulted in this output:

PHP Fatal error:  Uncaught DateMalformedStringException: Failed to parse time string (2022W1) at position 5 (1): Unexpected character in test.php:7
Stack trace:
#0 /root/test.php(7): DateTimeImmutable->__construct()

But I expected this output instead: a correctly set DateTimeImmutable object.

It seems that the parser refuses to recognize the "W" for week specification.

PHP Version

PHP 8.4.14 (cli) (built: Oct 21 2025 19:23:55) (NTS gcc x86_64)
Copyright (c) The PHP Group
Built by Fedora Project
Zend Engine v4.4.14, Copyright (c) Zend Technologies

Operating System

Fedora 42

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions