TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-23-2009, 06:40 PM   #1 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default On an interesting note

PHP Code:

abs
(ceil((strtotime($endDate) - strtotime($startDate)) / 86400)) 

Curiously, I got a negative number for this - PHP breaking the rules of math?
Enfernikus is offline  
Reply With Quote
Old 04-23-2009, 06:45 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

What do $endDate and $startDate equal? What makes you think it's breaking the rules of mathematics?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 04-23-2009, 07:17 PM   #3 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

no matter what $endDate and $startDate equate to, abs() should make it positive. the absolute value of a negative is a positive.
Enfernikus is offline  
Reply With Quote
Old 04-23-2009, 07:28 PM   #4 (permalink)
The Gregarious
 
allworknoplay's Avatar
 
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
allworknoplay is on a distinguished road
Default

When I do this, I get a positive number of 10.


$startDate = "20 September 2000";
$endDate = "10 September 2000";

$test = abs(ceil((strtotime($endDate) - strtotime($startDate)) / 86400));


echo $test;
allworknoplay is offline  
Reply With Quote
Old 04-23-2009, 09:19 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Either your abs function is not working or something is happening to the data between the assigning and output. No real number can have a negative absolute value, an exception would have been thrown.
__________________

Village Idiot is offline  
Reply With Quote
Old 04-24-2009, 11:54 AM   #6 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

try to do it manually, see if it produces the same result, if not there may be somethings b0rked with abs, don't quite know what mind you, but just limit the possible avenues of error.

PHP Code:
function negToPos ($i)
{
    return 
$i ? -$i $i;
}
$startDate "20 September 2000";
$endDate "10 September 2000";
$test negToPos(ceil((strtotime($endDate) - strtotime($startDate)) / 86400));
echo 
$test
gives me, int 10 (as does the original abs() implementation)
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 04-24-2009 at 01:15 PM. Reason: typo in function name, not that it matters! but hey.
sketchMedia is offline  
Reply With Quote
Old 04-24-2009, 12:13 PM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

To be frank, this thread is pointless unless it can be repeated. Does that code still return negative? What were the values of $startDate and $endDate which returned the negative value?
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Next class project? allworknoplay The Lounge 6 04-18-2009 08:33 PM
Interesting job you've done? TlcAndres The Lounge 0 03-31-2008 03:49 PM
A rather interesting page TlcAndres The Lounge 4 01-04-2008 10:04 PM


All times are GMT. The time now is 10:40 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design