Okay, I have spent a lot of time simplifying this formula. I attached an image of the new version. This is actually the 3rd revision I have made. The last one I didn't post because it was only slightly nicer than the one above.
Here is the code in VB.
VB Code:
Private Function ConvertToDayOfWeek3( _ ByVal M As Long, _ ByVal D As Long, _ ByVal Y As Long _ ) As Long Dim lReturn As Long Dim lYearStart As Long Dim lMonthOffset As Long Dim lDay As Long Dim lLeapYearAfterFeb As Long lYearStart = Int(365.25 * (Y - 1)) lMonthOffset = Int(530526416330# / 10 ^ (M - 1)) - Int(530526416330# / 10 ^ M) * (10) lLeapYearAfterFeb = (1 - Int((Y Mod 4) / (Y Mod 4 - 0.01))) * Int(Int(M / 3) / (Int(M / 3) - 0.0001)) lDay = D - 1 lReturn = (lYearStart + lMonthOffset + lDay + lLeapYearAfterFeb) Mod 7 ConvertToDayOfWeek3 = lReturn End Function




Reply With Quote