Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #5039 > unrolled thread

strtotime() not able to handle 04/29 correctly???

Started bycerr <ron.eggler@gmail.com>
First post2012-02-29 10:41 -0800
Last post2012-03-01 01:28 +0000
Articles 7 — 6 participants

Back to article view | Back to comp.lang.php


Contents

  strtotime() not able to handle 04/29 correctly??? cerr <ron.eggler@gmail.com> - 2012-02-29 10:41 -0800
    Re: strtotime() not able to handle 04/29 correctly??? "Peter H. Coffin" <hellsop@ninehells.com> - 2012-02-29 14:19 -0600
    Re: strtotime() not able to handle 04/29 correctly??? Jerry Stuckle <jstucklex@attglobal.net> - 2012-02-29 16:21 -0500
    Re: strtotime() not able to handle 04/29 correctly??? Doug Miller <doug_at_milmac_dot_com@example.com> - 2012-02-29 23:24 +0000
      Re: strtotime() not able to handle 04/29 correctly??? Eli the Bearded <*@eli.users.panix.com> - 2012-03-01 00:25 +0000
        Re: strtotime() not able to handle 04/29 correctly??? The Natural Philosopher <tnp@invalid.invalid> - 2012-03-01 00:46 +0000
        Re: strtotime() not able to handle 04/29 correctly??? Doug Miller <doug_at_milmac_dot_com@example.com> - 2012-03-01 01:28 +0000

#5039 — strtotime() not able to handle 04/29 correctly???

Fromcerr <ron.eggler@gmail.com>
Date2012-02-29 10:41 -0800
Subjectstrtotime() not able to handle 04/29 correctly???
Message-ID<a63a7827-bc1a-483a-96ae-de8289aa2de0@32g2000yqn.googlegroups.com>
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

[toc] | [next] | [standalone]


#5040

From"Peter H. Coffin" <hellsop@ninehells.com>
Date2012-02-29 14:19 -0600
Message-ID<slrnjkt22c.rcn.hellsop@nibelheim.ninehells.com>
In reply to#5039
On Wed, 29 Feb 2012 10:41:34 -0800 (PST), cerr wrote:
> 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?

"Note:

Using this function for mathematical operations is not advisable. It is
better to use DateTime::add() and DateTime::sub() in PHP 5.3 and later,
or DateTime::modify() in PHP 5.2."

Be that as it may...

What result are you expecting? 2012-02-29 to 2012-04-01 is 32 days isn't
it? Plus the 1 you're adding for no obvious reason would be 33, and 
rounding the result you *did* get comes out 33..

-- 
"The last refuge of the insomniac is a sense of superiority to the
 sleeping world."
                --Leonard Cohen, The Favourite Game

[toc] | [prev] | [next] | [standalone]


#5041

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-02-29 16:21 -0500
Message-ID<jim4st$184$1@dont-email.me>
In reply to#5039
On 2/29/2012 1:41 PM, cerr wrote:
> 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

Daylight savings time.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#5042

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2012-02-29 23:24 +0000
Message-ID<XnsA008BB3182026dougmilmaccom@88.198.244.100>
In reply to#5039
cerr <ron.eggler@gmail.com> wrote in news:a63a7827-bc1a-483a-96ae-de8289aa2de0@
32g2000yqn.googlegroups.com:

> 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

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.

[toc] | [prev] | [next] | [standalone]


#5043

FromEli the Bearded <*@eli.users.panix.com>
Date2012-03-01 00:25 +0000
Message-ID<eli$1202291918@qz.little-neck.ny.us>
In reply to#5042
In comp.lang.php, Doug Miller  <doug_at_milmac_dot_com@example.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" and in some regions only. Arizona is
unaffected. Parts of Indiana, too. Years before 2007 don't have the
second Sunday of March significant at all.

Elijah
------
would rather do away with this whole daylight savings time business

[toc] | [prev] | [next] | [standalone]


#5044

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2012-03-01 00:46 +0000
Message-ID<jimgsf$5d1$4@news.albasani.net>
In reply to#5043
Eli the Bearded wrote:

> 
> Elijah
> ------
> would rather do away with this whole daylight savings time business

+1

-- 
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.

[toc] | [prev] | [next] | [standalone]


#5045

FromDoug Miller <doug_at_milmac_dot_com@example.com>
Date2012-03-01 01:28 +0000
Message-ID<XnsA008D03397060dougmilmaccom@88.198.244.100>
In reply to#5043
Eli the Bearded <*@eli.users.panix.com> wrote in news:eli$1202291918@qz.little-
neck.ny.us:

> In comp.lang.php, Doug Miller  <doug_at_milmac_dot_com@example.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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web