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 05-28-2011, 10:52 PM   #1 (permalink)
The Wanderer
 
Join Date: Jan 2010
Posts: 13
Thanks: 0
pepelepew1962 is on a distinguished road
Default strtotime calculations inaccurate ...

//
I am trying to calculate the number of days between dates and have a major problem. When I try the example below, it gives me exactly 201 days, yet the dates have different times, meaning that a full day is impossible. If it matters, I am testing via xampp 1.7.3 with php version 5.3.1 with Windows XP. Can anyone explain what I am doing wrong. Can daylight savings play a role?

$frmritedate7116 = strtotime('2010-12-13 23:00');
$frmritedate7156 = strtotime('2010-05-27 00:00');
//
$frmritedate7251 = $frmritedate7156 - $frmritedate7116;
//
//
1274943600-1292310000=-17366400 // 86400 seconds in a day ( 201.00 )
//
//
//
pepelepew1962 is offline  
Reply With Quote
Old 06-01-2011, 06:46 AM   #2 (permalink)
The Wanderer
 
Join Date: May 2010
Posts: 19
Thanks: 1
core1024 is on a distinguished road
Default

Hi! This is due DST.
Just take a look in this example:
vlado@testing-pc:~$ php -r 'date_default_timezone_set("UTC"); echo ((strtotime("2010-12-13 23:00") - strtotime("2010-05-27 00:00"))/ 86400).chr(10);'
200.95833333333
vlado@testing-pc:~$ php -r 'date_default_timezone_set("Europe/Sofia"); echo ((strtotime("2010-12-13 23:00") - strtotime("2010-05-27 00:00"))/ 86400).chr(10);'
201
vlado@testing-pc:~$
core1024 is offline  
Reply With Quote
Old 02-19-2012, 12:47 PM   #3 (permalink)
The Visitor
 
Join Date: Feb 2012
Posts: 2
Thanks: 0
omfgitsasalmon is on a distinguished road
Default

Take a look at this article I wrote before, it should fix your needs.

http://omfgitsasalmon.posterous.com/...dnt-know-exist
omfgitsasalmon 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


All times are GMT. The time now is 06:17 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