RE: [PHP] Within the date format
| From: | Demitrious S. Kelly | Date: | Fri, 19 Apr 2002 16:20:51 +0000 |
| Subject: | RE: [PHP] Within the date format | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-93729@lists.php.net to get a copy of this message | ||
Whatever works
And the function works fine for any year after 2000
Besides... it was just a quick and dirty example
-----Original Message-----
From: Miguel Cruz [mailto:mnc@stoic.net]
Sent: Friday, April 19, 2002 9:14 AM
To: Demitrious S. Kelly
Cc: php-general@lists.php.net
Subject: RE: [PHP] Within the date format
1) That function isn't correct.
2) It's slow.
3) You still would have to call it once for each year in the range in
order to figure out how many intervening leap years there are, and you'd
have to check whether the dates in question fell before or after Feb 29.
Much easier to just calculate the difference of days, months, and years.
BTW, off the top of my head (untested), here's a more accurate (and a
million times faster) way to check for a leap year:
function is_leap ($year)
{
return (!($year % 4) && (($year % 100) || !($year % 400)));
}
miguel
On Fri, 19 Apr 2002, Demitrious S. Kelly wrote:
> function is_leap($yyyy) {
> $leap=0;
> $refy=2000;
> while ( $yyyy >= $refy ) {
> if ( $refy == $yyyy ) {
> $leap=1;
> } else if ( $refy > $yyyy ) {
> break;
> }
> $refy++;
> $refy++;
> $refy++;
> $refy++;
> }
> return($leap);
> }
>
> -----Original Message-----
> From: Miguel Cruz [mailto:mnc@stoic.net]
> Sent: Friday, April 19, 2002 8:52 AM
> To: Demitrious S. Kelly
> Cc: php-general@lists.php.net
> Subject: RE: [PHP] Within the date format
>
> Like I said, if it crosses through a leap year, your calculation may
be
> off. How many days are there in February when you don't know what year
> it
> is?
>
> miguel
>
> On Fri, 19 Apr 2002, Demitrious S. Kelly wrote:
> > Wouldn't it be easier to convert each date into a unix timestamp,
then
> > subtract... the resulting number is the difference in seconds. Then
> > devide by 60 for minutes, again for hours 24 for days, etc, etc
> >
> >
> > -----Original Message-----
> > From: Miguel Cruz [mailto:mnc@stoic.net]
> > Sent: Friday, April 19, 2002 8:44 AM
> > To: Ron Allen
> > Cc: php-general@lists.php.net
> > Subject: Re: [PHP] Within the date format
> >
> > On Fri, 19 Apr 2002, Ron Allen wrote:
> > > This is what I have right now
> > >
> > > $totaltime= date(":H:i:s", mktime(0,0,$totaltime));
> > >
> > > This is the result
> > >
> > > 04:20:46
> > >
> > > from the following dates
> > > 2002-04-25 16:30:16
> > > 2002-04-19 12:09:30
> > > 534046 seconds
> > >
> > > I would like to be able to get the days and, if needed, the number
> of
> > months
> > > and years
> >
> > Well, I think the easiest way is going to be to split your date
apart
> > into
> > $day, $month, $year and then subtract.
> >
> > You can't just do a cascading modulus calculation on the delta
between
> > the
> > timestamps, because that won't take leap years into account.
> >
> > miguel
> >
> >
> >
>
>
>