|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54582 Division is not preferred to substraction
Submitted: 2011-04-21 03:55 UTC Modified: 2011-04-21 04:04 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: fs at coresec dot de Assigned:
Status: Not a bug Package: Math related
PHP Version: 5.3SVN-2011-04-21 (snap) OS: Debian Squeeze
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: fs at coresec dot de
New email:
PHP Version: OS:


 [2011-04-21 03:55 UTC] fs at coresec dot de
When dealing with a MySQL-Datetime Tiemstamp i've encountered the following Bug which leads to an error resulting in a wrong integer (resulting days).

$mysql is an array containing a mysql datetime at point [6] "2011-06-21"

If $mysql[6] is in the future and time() is the present unix-timestamp we're getting a wrong result in $remaining (days).

Test script:
$remaining = floor(strtotime(str_replace('-','',$mysql[6])) - time()/(60*60*24));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-21 04:04 UTC]
-Status: Open +Status: Bogus
 [2011-04-21 04:04 UTC]
You might want to rethink your code there :)

time()/60*60*24 is going to give you the approximate number of days since 1970 
which is a bit over 15000. your strtotime() is going to return the number of 
seconds since 1970.  Then you subtract the number of days from the number of 
seconds? That makes no sense, but PHP is doing exactly what you are asking for.

You should be using for stuff like this anyway, not 
 [2011-04-21 04:07 UTC] fs at coresec dot de

I'm so sorry about this - pretty late here in Germany :(
It was absolutely my fault as i didnt set the brakets correctly.

$remaining = floor((strtotime(str_replace('-','',$proxy[6])) - time())/(60*60*24));

Works as aspected - i am sorry for this bugreport - should have triple-checked it before posting it.

Have a sunny weekend guys!
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 03:01:31 2024 UTC