First, let me introduce some variables:
The value of v corresponds to the day of week in the following way: 0 is Sunday, 1 is Monday, 2 is Tuesday, ...., and 6 is Saturday.
As an example, let us calculate the day of the week for Jan 8, 1995:
Here, d = 8, m = 11, Y = 1994, c = 19 and y = 94.
A = int(28.4) + 8 + 94 + int(94/4) + int(19/4) - 38 = 119
v = 119 mod 7 = 0
Jan 8, 1995 is a Sunday! Check your calendar and see if it's correct!
Important Note:
Due to the perculiarity of the mod function for negative numbers
in many programming languages, the above formula may seem wrong when programmed.
In most programming languages, (-x) mod y is equivalent to
x mod y, which is not the correct mathematical definition of
mod, hence the problem.
To get around this problem, you can define your own mod function
to take care of negative numbers. When computing x mod y, after
computing the mod, see if it is zero. If it is, leave it.
If not, then subtract the result from y. For example, when computing
-5 mod 4, the C language will give you 1.
Subtracting from 4 gives 4 - 1 = 3.