User Tools

Site Tools


mmbasic:compact_quick_day_of_week_function_with_historical_capability

Compact Quick Day Of Week function with historical capability

Fast,compact Day of the Week function that correctly handles pre 2001 dates correctly

credit: TBS user MicroBlocks, the original thread can be seen here: http://www.thebackshed.com/forum/forum_posts.asp?TID=6235&KW=weekday&PN=1&TPN=1

It has been tweaked here to add typing to the function and local variables

Function DayOfWeek(year As Integer,month As Integer,day As Integer) As Integer
' sun mon tue wed thu fri sat
'  0   1   2   3   4   5   6
  local integer a,m,y
  a = int((14-month)/12) 
  m = month + 12*a - 2 
  y = year - a 
  DayOfWeek = (day + y + int(y/4)-int(y/100)+int(y/400)+int(31*m/12)) mod 7 
End Function 
mmbasic/compact_quick_day_of_week_function_with_historical_capability.txt · Last modified: 2024/01/19 09:30 by 127.0.0.1