This could be for any language. Should be pretty easy.
don't you hate when you work on something, and you get brainfreeze and all of sudden you're dumber than a box of rocks...
anyway, here's the deal. you are given:
0 = sunday ... 6 = saturday
//I personally prefer 1-7, but...
startday of given month. ie. for jan 2003, the first is on a wednesday, or as defined 3.
a day of the month. for jan 2003, 1-31.
return the day of the week for the day of the month.
so if we have integer calcdow(int startday, int dayofmonth), the above example would be
calcdow(3, 1) returns 3.
or
calcdow(3, 15) returns 3. as today is wednesday.
a very poor way would be:
Code:
public integer calcdow(int startday, int dayofmonth)
{
for (int i= 1; i < dayofmonth; i++)
{
startday++;
if (startday == 7)
{
startday =0;
}
}
return startday;
} DOH!, brainfreeze just left, nevermind, as:
dayofweek = dayofmonth%7 + startday - 1;
sometimes you just have to step away from the issue....