Returns the day of the week for a calendar date.
good example of math & table use.
Note: needed to convert "w" to integer to get the table string associated day.
source matlab code:
Code: Select all
function w = Wd(m,d,cy)
m = m-2;
if m <= 0, m = m+12; cy = cy-1; end;
c = fix(cy/100);
y = mod(cy,100);
w = mod(d+fix(m*2.59)+fix(y*1.25)+fix(c*5.25),7);
%example
w = Wd(1,6,2016)
%returns
w=3
Code: Select all
global getday = function(m,d,cy)
{
day = table("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
m = m-2;
if (m <= 0)
{
m = m+12;
cy = cy-1;
}
c = math.floor(cy/100);
y = (cy % 100);
w = ((d+math.floor(m*2.59)+math.floor(y*1.25)+math.floor(c*5.25)) % 7);
w = ToInt(w);
return day[w];
};
weekday=getday(1,11,2016); // todays date returned as #1 Monday
print("The day of the week was: "+weekday);