Quick Day Of Week (and tiny too)

Modified on 2017/08/04 08:49 by CaptainBoing — Categorized as: Dates, Time and Clocks, Encode and Decode, Maths

Caution - do not use for dates prior to 01 MAR 2000 - read discussion If you need historical DayofWeek, here is an alternative

This has to be the fastest most compact Day of the Week function I have seen.

credit: TBS user Quazee137 the original thread can be seen here: http://www.thebackshed.com/forum/forum_posts.asp?TID=9281&TPN=2


Function dow(m As Integer,d As Integer,y As Integer) As Integer

'  1       2       3       4       5       6       7
' sun     mon     tue     wed     the     fri     sat

   If m < 3 Then
      m=m + 12
      y=y-1
   End If
   dow = 1 + (d + ((26 * m+1)/10) - (2 * (y\100)) + y + (y\4) + (y\400) ) Mod 7
End Function