Well, given any starting date for which you know the day of week, you would work
with the difference in days modulo 7. But of course the real issue is how to
count up that difference in days. All you really need is the leap year rules:
1) Every year divisible by 4 is a leap year, EXCEPT
2) Every year divisible by 100 is NOT a leap year, EXCEPT
3) Every year divisible by 400 IS a leap year, EXCEPT
4) (I don't know where the next exception falls, but these first
3 should be good enough for anything since Year 0, at least)
So in essence you apply the above rules to count the number of days in each year
until you get to the target year, then start counting days per month (watch out
for February) until you get to the target month, etc.
This is a simple-minded way to go about it of course, and somewhat less trivial
to code correctly than it probably sounds, but it is good enough for reasonable
time spans. Low-level system utilities which must do this sort of calculation
as quickly as possible use highly optimized code and every mathematical trick in
the book.
HTH,
-rick-
Pohihihi wrote:
ah, again I did.
I should have said I want to know how to make my own DateTime kind of
function. Just want to know the math behind.
"Rick Lones" <Wr******@YcharterZ.net> wrote in message
news:xs*****************@fe03.lga...
Pohihihi wrote:
where can I get code/process/algorithm/or any kind of example to
calculate what day of the week (or month or year) is say 5th of sep in
1767.
DateTime dt = new DateTime(1767,9,5);
string s = dt.DayOfWeek.ToString();
HT H,
-rick-