On Tue, 25 Jan 2011, John Pickard wrote: > > If you need to check days of weeks for arcane dates, JoneSoft Date Calculator > is a free program that will give you the day of the week for just about any > date, and the number of days between two specific dates.
You only need about two lines of code to turn a Gregorian date into a count of days, and from that it's trivial to get the day of the week or the interval between to dates. Of course it's no use for historical dates when you need to care about old style vs. new style, never mind the confusion caused by nautical or astronomical notations! The following takes a date in conventional notation and returns a "rata die" day number, as defined by Reingold and Dershowitzin in "Calentrical Calculations" (published by Cambridge University Press). Their formulae are rather more general than mine and not so optimised for brevity. Mon 0001-01-01 (according to the proleptic Gregorian calendar) is R.D. 1 Wed 1858-11-17 is R.D. 678576 and Modified Julian Day number 0 The remainder after dividing an RD by 7 is the day of the week, numbered from zero (Sunday) to six (Saturday). int gregorian_to_rd(int y, int m, int d) { if (m > 2) m += 1; else m += 13, y -= 1; return y*1461/4 - y/100 + y/400 + m*153/5 + d - 428; } gregorian_to_rd(2011,1,25) == 734162 734162 % 7 == 2 The reverse calculation is rather more complicated! A couple of years ago I wrote up detailed explanations of how these calculations work: http://fanf.livejournal.com/93326.html http://fanf.livejournal.com/93771.html Tony. -- f.anthony.n.finch <d...@dotat.at> http://dotat.at/ HUMBER THAMES DOVER WIGHT PORTLAND: NORTH BACKING WEST OR NORTHWEST, 5 TO 7, DECREASING 4 OR 5, OCCASIONALLY 6 LATER IN HUMBER AND THAMES. MODERATE OR ROUGH. RAIN THEN FAIR. GOOD. --------------------------------------------------- https://lists.uni-koeln.de/mailman/listinfo/sundial