php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81569 Relative time with decimal value
Submitted: 2021-10-30 10:25 UTC Modified: 2021-10-30 19:31 UTC
From: tm8544 at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 8.1.0RC5 OS: Windows 10 x64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tm8544 at hotmail dot com
New email:
PHP Version: OS:

 

 [2021-10-30 10:25 UTC] tm8544 at hotmail dot com
Description:
------------
In PHP Manual
›Supported Date and Time Formats
›Relative Formats

number format is
[+-]?[0-9]+
, no decimal point included.

If number is given with decimal value, number should be cut before decimal point, eg "+1.5" should be read as "+1"
Now, it is read as "5"




Test script:
---------------
<?php

// in examples below, this script was run at 30.10.2021

echo date("j.n.Y", strtotime("+1.5 year", time()));
echo date("j.n.Y", strtotime("-1.5 year", time()));

?>


Expected result:
----------------
30.10.2022
// 1 year ahead

30.10.2020
// 1 year backwards

Actual result:
--------------
30.10.2026
// This is 5 years ahead, not 1.5 years ahead

30.10.2026
// This is 5 years ahead, not 1.5 years backwards



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-30 19:31 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2021-10-30 19:31 UTC] requinix@php.net
You aren't seeing the full picture with just the date portion.

https://3v4l.org/gMsML

As with other miscellaneous inputs that don't have meaning to the parser, the decimal point acts as a separator, so "+1.5 year" means "+1" and then "5 year".

"+1" is a tzcorrection. https://www.php.net/manual/en/datetime.formats.time.php
"5 year" is a relative amount. https://www.php.net/manual/en/datetime.formats.relative.php

The result is +1 or -1 hour for the timezone correction and 5 years added to the date.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 20:01:30 2025 UTC