This code snippet demonstrates how to calculate the day of the week from a specific date using mathematical formulas. The result is a number from 1 to 7, where each number corresponds to a day of the week (e.g., 1 for Sunday, 2 for Monday, etc.).
//find the day number with a date
myYear=Year
myMonth=Month
myDay=Day
if myMonth >= 3 then
D = (((23*myMonth)/9) + myDay + 4 + myYear + (myYear/4) - (myYear/100) + (myYear/400) - 2) mod 7
else
z = myYear - 1
D = (((23*myMonth)/9) + myDay + 4 + myYear + (z/4) - (z/100) + (z/400) ) mod 7
endif
return d
The code snippet above calculates the day of the week for a given date specified by the variables myYear, myMonth, and myDay. Here’s a step-by-step explanation of how it works:
This method is based on a variation of Zeller’s Congruence, a well-known algorithm to calculate the day of the week for any Julian or Gregorian calendar date.
Check out this related content for more information:
https://www.prorealcode.com/topic/how-to-avoid-bank-holidays-in-trading-system/#post-75415
Visit Link