Welcome Guest, you are in: Login

Fruit Of The Shed

Navigation (MMBasic)






Search the wiki

»


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