Is there any fast way to get the number of a certain day in a week

I'm realy sorry, if this question is a bit stupid... But this is my first time on mathematics stackexchange.

Do you guys now for example, how to know the number of monday in a year?

-
It depends on the year. – Henry Nov 13 '12 at 22:42
Yes, I can derive a formula for it. – timur Nov 13 '12 at 22:44
The question does not make sense, you do mean "the number of x day in a year" right? – picakhu Nov 13 '12 at 22:46
@F'OlaYinka: Your answer is perfectly fine apart from the easily fixed "$51$" typo. – André Nicolas Nov 13 '12 at 23:15
Thanks every one – Madou Nov 14 '12 at 7:34

This program computes days of the week for modern dates. You can step through the lines and attempt to glob together a compressed formula.

def isLeap(year):
if year % 4 != 0:
return False
if year % 400 == 0:
return True
if year % 100 == 0:
return False
return True
## years divisible by 4, but not 100 are leap years, unliess
##they are divisible by 400.

def dayOfWeek(day, month, year):
y = year - 1
total = y %7
total += (y//4 - y//100 + y//400)%7
total %= 7
daysInMonths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if isLeap(year):
daysInMonths[2] += 1
for k in range(month):
total +=daysInMonths[k]
total += day
total %= 7
dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
return dayNames[total]

print (dayOfWeek(26, 5, 1957))
print (dayOfWeek(13,11,2012))

-
thank you very much – Madou Nov 14 '12 at 7:01

There are 365 days in a non-leap year. If you divide by 7 (the number of days in a week) you get

$$\frac{365}{7} = 52 \frac{1}{7}$$

which means that in a non-leap year, there are 52 full weeks, with one day left over. Therefore there will be one day that occurs 53 times, with the other days occuring 52 times.

The day that occurs 53 times will be the one on the first day of the year. For example, in 2011 the first day of the year was a Saturday, which means that there were 53 Saturdays in 2011, and 52 of every other day.

2012 is a leap year. That means that there are two days that appear 53 times (whichever days the 1st and 2nd January fall on). In 2012 the 1st Jan was a Sunday, and the 2nd Jan was a Monday. So in 2012, there will be 53 Sundays and Mondays, and 52 of every other day.

-
See also en.wikipedia.org/wiki/… for a formula to determine which day of the week January 1 is in a particular year. – Robert Israel Nov 13 '12 at 22:55

There are 52 Mondays unless a) Jan 1 is a Monday or b) Jan 1 is a Sunday and the year is a leap year. In that case there are 53. Various algorithms for calculating day of week are available many places on the web. One page that has many formats is this one.

-