Home »
Imported messages »
comp.lang.php »
strtotime() not able to handle 04/29 correctly???
strtotime() not able to handle 04/29 correctly??? [message #177220] |
Wed, 29 February 2012 18:41  |
cerr
Messages: 33 Registered: September 2010
Karma: 0
|
Member |
|
|
Hi,
I calculate the amount of days between two dates like this:
$start = strtotime($_SESSION['sdate']);
$end = strtotime($_SESSION['hdate']);
echo ($end - $start);
$duration = ($end - $start) / 3600 /24;
$duration+=1; //plus one day
echo " The ad will show for ".$duration." day(s)<br/>";
Which generally works fine but things seem to mess up when I have a
start sdate of 2012-02-29 and an hdate of 2012-04-01. I get a duration
of: 32.9583333333
Why is this? That's messing up my calculations. Is there a better way
to do this?
Thanks!
Ron
|
|
|
|
|
|
|
|
Re: strtotime() not able to handle 04/29 correctly??? [message #177226 is a reply to message #177224] |
Thu, 01 March 2012 01:28  |
Doug Miller
Messages: 171 Registered: August 2011
Karma: 0
|
Senior Member |
|
|
Eli the Bearded <*@eli.users.panix.com> wrote in news:eli$1202291918(at)qz(dot)little-
neck.ny.us:
> In comp.lang.php, Doug Miller <doug_at_milmac_dot_com(at)example(dot)com> wrote:
>> which is 32 days 23 hours. What might throw this off by one hour? Hint:
>> in the United States, it happens every year on the second Sunday of March.
>
> For some values of "every year"
Oh, really? You think the DST transition occurs only some years, and not others?
> and in some regions only. Arizona is unaffected.
Correct. Hawaii also.
> Parts of Indiana, too.
Incorrect. All of Indiana observes DST.
> Years before 2007 don't have the
> second Sunday of March significant at all.
Years before 2007 were not part of the OP's date range and thus are not relevant to this
discussion.
|
|
|
Goto Forum:
Current Time: Sun Apr 13 23:49:17 GMT 2025
Total time taken to generate the page: 0.08400 seconds