Page 1 of 1

Determining the day of the week

Posted: Fri May 19, 2006 7:31 pm
by Aeros
Here's how to determine the day of the week, given the current date. Note that you will need to write your own script to determine the values of MM2, DD and YY. Hope this helps you. (Please note that this only works for dates between the year 2000 and 2099)

DD = day of current date
MM2 = month of current date (March = 3, November = 11, etc)
YY = last two digits of the current year (2006 = 6, etc)

Code: Select all

	var MM;
	case(MM2)
		1:	MM := 1;
		2:	MM := 4;
		3:	MM := 4;
		4:	MM := 0;
		5:	MM := 2;
		6:	MM := 5;
		7:	MM := 0;
		8:	MM := 3;
		9:	MM := 6;
		10:	MM := 1;
		11:	MM := 4;
		12:	MM := 6;
	endcase
	
	var a := Cint(YY / 4) + DD + MM + 6 + YY;
	var b := a / 7;
	var c := Cint(a - (7 * b));
	
	var d;
	case(c)
		1:	d := 0;
		2:	d := 1;
		3:	d := 2;
		4:	d := 3;
		5:	d := 4;
		6:	d := 5;
		0:	d := 6;
	endcase
		
	return d;
Values for d:

0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday
6 = Saturday

Posted: Sat May 20, 2006 11:40 am
by Matrix
Well, it sounds to be another Millenar bug in 2099

Posted: Sat May 20, 2006 2:17 pm
by Aeros
No, there isnt a bug. That 6 that im adding just changes according to the century, by using the Key Value Method:

1600's, 2000's, 2400's, 2800's = 6
1700's, 2100's, 2500's, 2900's = 4
1800's, 2200's, 2600's, 3000's = 2
1900's, 2300's, 2700's, 3100's = 0