Advertisement
Arc13

WeekDay algorithm

Sep 28th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.33 KB | None | 0 0
  1. function getWeekDay(nY, nM, nD)
  2.   if not nD then
  3.     return false, "getWeekDay(year, month, date)"
  4.   end
  5.  
  6.   local a = math.floor((14 - nM) / 12)
  7.   local y = nY - a
  8.   local m = nM + 12 * a - 2
  9.  
  10.   local d = (nD + nY + math.floor(nY / 4) - math.floor(nY / 100) + math.floor(nY / 400) + math.floor((31 * m) / 12)) % 7
  11.  
  12.   return d
  13. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement