php.net |  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
Votes:1
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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: fs at coresec dot de
New email:
PHP Version: OS:

 

 [2011-04-21 03:55 UTC] fs at coresec dot de
Description:
------------
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:
----------------
29

Actual result:
--------------
1305920914

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-21 04:04 UTC] rasmus@php.net
-Status: Open +Status: Bogus
 [2011-04-21 04:04 UTC] rasmus@php.net
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 http://php.net/datetime for stuff like this anyway, not 
timestamps.
 [2011-04-21 04:07 UTC] fs at coresec dot de
OMFG! 

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: Thu Apr 18 00:01:28 2024 UTC