Ahh, date math... I spent 2 weeks trying to solve this once. I'm not
exactly sure what you are trying to calculate here. If you want the
number of days since the year 1601, no problem. I'm not sure where you
get your 1461 from, tho...
here's an algorthm I did in perl, which is fairly similar:
my %day_counts = (1 => 0,
2 => 31,
3 => 59,
4 => 90,
5 => 120,
6 => 151,
7 => 181,
8 => 212,
9 => 243,
10 => 273,
11 => 304,
12 => 334);
$day_count = (($year-1601)*365)+(int(($year-1601)/4));
$day_count += $day_counts{$perp_month};
$day_count += $day;
# leap year
if (int(($year-1600)/4) eq 0) {
if ($month > 2) {
$day_count++;
}
}
# adjust for leap year values that aren't a leap year
foreach my $key (1700,1800,1900,2100,2200,2300,2500,2600,2700) {
if ((($year == $key) && ($month > 2)) || ($year > $key)) {
$day_count--;
}
}
If anyone cares to translate into php, might be nice to have, but
doesn't php have a pretty good set of calendaring functions already?
haven't used 'em yet, but i looked at 'em a little...
johnny p.
> -----Original Message-----
> From: Miguel Loureiro [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 31, 2001 11:36 AM
> To: php-gen
> Subject: [PHP] Is correct ??
>
>
> Hi,
> Anybody knows if this sourcecode is correct to calculate the
> numbers of days in certain date ?
>
> $m - month; $d - day, $y - year
> if($m<=2){
>
> $y--;
>
> $m+=13;
>
> }
>
> else
>
> $m++;
>
> $nd = (1461 * $y / 4) + (153*$m/5) + $d;
>
> Because I use this code in a function and sometimes it your
> and others dont ....
>
> Best Regards
>
> Miguel Loureiro < [EMAIL PROTECTED] >
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]