How a calendar is calculated...

Pastore

Diamond Member
Feb 9, 2000
9,728
0
76
I am trying to code a little calendar to use as a scheduler, and I have no idea how to set up a calendar... Like what is the day of June 8, 2008? is their a specific formula to use to figure it out? or a simple little algorithm? thanks
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
a = (14 - month) / 12
y = year - a
m = month + 12*a - 2
For Julian calendar: d = (5 + day + y + y/4 + (31*m)/12) % 7
For Gregorian calendar: d = (day + y + y/4 - y/100 + y/400 + (31*m)/12) % 7

The value of d is 0 for a Sunday, 1 for a Monday, 2 for a Tuesday, etc.
 

Pastore

Diamond Member
Feb 9, 2000
9,728
0
76
what are the julian and gregorian calendars? and do i have to code something in for leep year?
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: Beast1284
what are the julian and gregorian calendars? and do i have to code something in for leep year?

rolleye.gif
damn you are fvcking lazy, i gave you the algorithm just use google and look it up!
 

fornax

Diamond Member
Jul 21, 2000
6,866
0
76
Since we all live by the Gregorian calendar, this is what you should use (well, Jews, Muslims, and some other use a Lunar calendar for some purposes :)) And the leap year rule is already coded in that algorithm (the y/4, y/100 and y/400 bits)