OK I know the DateTime structure is very good at doing this.
But if you ever wanted to design your own calendar, or just wanted to know how things are possibly done, this could be a handy function. Enjoy.
Calculate the daycode of a date
public int dateDaycode(int year, int month, int day)
{
//Using Zeller's formula
int d1, d2, d3, d4, code;
if (month == 1)
{
month = 13; year--;
}
if (month == 2)
{
month = 14; year--;
}
d1 = year / 4;
d2 = year / 100;
d3 = year / 400;
d4 = day + 2 * month + 3 * (month + 1) / 5 + year;
code = (d4 + d1 - d2 + d3 + 1) % 7;
return code;
// code will be sun=0,mon=1,tue=2,wen=3,thu=4,fri=5,sat=6
}
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.