See Wikipedia to learn about this method to mentally compute the weekday of any date.
Check out the source code.