1. Days and Years
Anybody know how to obtain the day when given a particular date?
And how about calculating how many, say, Fridays, are in a particular
month. For instance, there are four Mondays in January 1998 and five
Fridays in the same month.
Links or actual code would be appreciated and acknowledgments liberally made.
Thanks in advance!
ck
2. Re: Days and Years
C.K. asked:
> Anybody know how to obtain the day when given a particular date?
On the Archive page (at the very bottom), Junko Miura (RDS) has a small
program that will calculate the day of the week, given the date.
It will also calculate the number of days between two dates.
> And how about calculating how many, say, Fridays, are in a particular
> month. For instance, there are four Mondays in January 1998 and five
> Fridays in the same month.
Call her routine for each date in the month (be careful about
February 29) and see how many times it reports "Friday",
or whatever.
Regards,
Rob Craig
Rapid Deployment Software
3. Re: Days and Years
Rob Craig writes:
>> And how about calculating how many, say, Fridays, are in a
>particular > month. For instance, there are four Mondays in
>January 1998 and five > Fridays in the same month.
>Call her routine for each date in the month (be careful about
>February 29) and see how many times it reports "Friday", or
>whatever.
>Regards, Rob Craig Rapid Deployment Software =
I would say, isn't it easier to find the first Friday in the month, and
than, in pseudocode:
Fridays =3D floor((days_in_month[month] - first_friday[month])/7) + 1.
For january 1998, this would be: floor((31-2)/7) + 1 =3D 5.
days_in_month can be calculated from a sequence:
days_in_month =3D {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
if isyearleap(year) then
days_in_month[2] =3D 29
end if
The function isyearleap():
-- SNIP ----------------------------------------------------------------
global function isyearleap(integer year)
-- Returns 1 if year is a leap year, 0 otherwise.
-- Source: "Practical Algorithms for Programmers"
-- By: Andrew Binstock and John Rex
if not remainder(year,4) =3D 0 then -- If year not divisible by=
4
return 0 -- it's not leap.
elsif year < 1582 then -- All years divisible by 4
were
return 1 -- leap prior to 1582.
elsif remainder(year,100) !=3D 0 then -- If year divisible by 4,
return 1 -- but not by 100, its leap.
elsif not remainder(year,400) =3D 0 then -- If year divisible by 100=
,
return 0 -- but not by 400, it's not
leap.
else
return 1 -- If divisible by 400, it's
leap.
end if
end function -- isyearleap
-- SNIP ----------------------------------------------------------------
Hope this helps,
Ad Rienks
4. Re: Days and Years
- Posted by "Christopher K. Lester" <cklester at FLASH.NET>
Jan 02, 1998
-
Last edited Jan 03, 1998
Thank you to Mr. Craig, and Junko, and Mr. Rienks! This will help me
continue development of my program.
'ppreciate ya!
ck