php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62353 strtotime fails to interpret time correctly, uses character after decimal point
Submitted: 2012-06-18 16:32 UTC Modified: 2016-06-17 18:13 UTC
Votes:4
Avg. Score:2.8 ± 1.8
Reproduced:2 of 3 (66.7%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: mike dot mackintosh at angrystatic dot com Assigned: cmb (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.4Git-2012-06-18 (snap) OS: Ubuntu 12.04 x86_64
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: mike dot mackintosh at angrystatic dot com
New email:
PHP Version: OS:

 

 [2012-06-18 16:32 UTC] mike dot mackintosh at angrystatic dot com
Description:
------------
PHP fails to interpret correctly the relative time string when a decimal is used. PHP will use the character after the decimal point as the multiplier/value in timelib_relative_time. Using an integer of 1.0, results in no change.

Test script:
---------------
echo date("m/d/y", strtotime("+1.5 years"));
echo date("m/d/y", strtotime("+1.0 years"));

Expected result:
----------------
12/18/13
06/18/13

Actual result:
--------------
06/18/17
06/18/12

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-06-18 16:48 UTC] mike dot mackintosh at angrystatic dot com
The following behavior is also present:

echo date("m/d/y H:i", strtotime("1.5 days ago"));

Results in -5 days, 5 hours.

It would be expected to return -1 day and 12 hours, being relative.
 [2012-06-18 16:51 UTC] mike dot mackintosh at angrystatic dot com
On 6/18/2012 12:50 PM Est, when running:

echo date("m/d/y H:i", strtotime("-1.0 day"));

The following is returned:

06/18/12 09:50

(Minus 3 hours).
 [2012-06-18 17:03 UTC] pajoye@php.net
fix cat
 [2012-06-18 17:03 UTC] pajoye@php.net
-Package: date_time +Package: Date/time related
 [2012-07-11 02:17 UTC] omg00dness at yahoo dot com
I don't see this as a bug.  I don't even see how you would want to rely on FRACTION units.  You always have leap seconds, leap years, localization, etc.  How do you measure half a year?  The <# of days> / 2?  6 months?  <# of seconds> / 2?  One day does not always equal 86,400 seconds.

Besides, the documentation clearly shows this is not supported.

**Go to: http://us.php.net/manual/en/function.strtotime.php

**Under the <time> parameter, click on Date and Time Formats, or go to: http://www.php.net/manual/en/datetime.formats.php

**Click on Relative Formats.

It seems like you are trying to do the row with:

Format: number space? (unit | 'week')
Description: Handles relative time items where the value is a number.
Examples: "+5 weeks", "12 day", "-7 weekdays"

If you look up <number> at the top of that same page, you have the regex: [+-]?[0-9]+
which clearly DOES NOT accept a decimal point.  It accepts +, -, or nothing, followed by one or more DIGITS.

Sorry if my formatting/caps seem a bit awkward or harsh, but I don't have the liberty to add tags here.
 [2016-06-17 18:13 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-06-17 18:13 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

For reference: <https://3v4l.org/qb1jp>.

As omg00dness already explained, this is expected behavior.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 15:01:30 2025 UTC