Finding out the weekday

Terry Reedy tjreedy at
Tue Mar 25 21:07:30 CET 2003

"Jorge Godoy" <godoy at> wrote in message
news:86adfjz286.fsf at
> Is there any Python module that given a particular date it returns
> the day of the week? I'm needing it for some special calculations
> involving dates...

don't know if new datetime module has that.  But formula is easy to
program.  This has been asked various times on various newgroups.
Google 'day week formula', first hit says
To add to Ben's article (appended below), John Conway's
method is by far the easiest to use. A general method
of finding the special day of the week for any year (what
Conway calls 'Doomsday') is as follows: Write the year
CCYY; eg, for 1994, CC=19 and YY= 94. Then calculate (this
is easy to do in your head)

  D = ((YY/12) + (YY mod 12) + ((YY mod 12)/4)) mod 7,

where '/' means divide and retain the integer part. For example,
in 1994, D = (94/12) + (94 mod 12) + ((94 mod 12)/4)
           = (7 + 10 + 2) mod 7 = 19 mod 7 = 5

Finally, in this century, add D to E=3 (mod 7) to get 1 (in 1994),
which is the day of the week (Sunday = 0, Saturday = 6). Thus,
Monday=1 is the Doomsday for 1994.

E is the century number, which repeats on a 400 year cycle.
This century E=3; in 16YY and 20YY it is 2; in 17YY and 21YY
it is 0, and in 18YY and 22YY it is 5. It goes back to 3 again
in 23YY.

Terry J. Reedy

More information about the Python-list mailing list