Skip to content

strtotime() has strange interpretation of decimal weeks #21027

@hartman

Description

@hartman

Description

The following code:

<?php
strtotime("2.37685 weeks");

Resulted in this output:

1613443020

The code interpreted 2.37685 weeks as 02:37 (hours) and 685 weeks. This is non logical input of course (and not GNU compliant). But this isn't a very logical interpretation of this value from a human perspective.

The parser decided to not be able to recognize weeks, then fallback to hours, interpret up to 2 decimals (compliant with hour parsing), then split the remainder and continue parsing, interpreting the rest as the input for weeks.

This has been a known issue for Wikipedia since 2007, but was never reported upstream.

PHP Version

PHP 8.4.16 (cli) (built: Dec 16 2025 16:03:34) (NTS)
Copyright (c) The PHP Group
Built by Homebrew
Zend Engine v4.4.16, Copyright (c) Zend Technologies
    with Xdebug v3.4.0, Copyright (c) 2002-2024, by Derick Rethans
    with Zend OPcache v8.4.16, Copyright (c), by Zend Technologies

Operating System

macos

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions