Day Of Week Interger and Name

Send Snippet To: Save this snippet to Code Collector Pro -- view all roger's snippets
language: Other
license: Other

Code for Snippet:

                
-- returns the day of week integer and the name of the week
-- Compatible with Lua 5.0 and 5.1.
-- from sam_lie 
function get_day_of_week(dd, mm, yy) 
  local days = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }
  local fullname={“Sunday”,”Monday”,”Tuesday”,”Wendsday”,
“Thursday”,”Friday”,”Saturday” }
 
  local mmx = mm
 
  if (mm == 1) then  mmx = 13; yy = yy-1  end
  if (mm == 2) then  mmx = 14; yy = yy-1  end
 
  local val8 = dd + (mmx*2) +  math.floor(((mmx+1)*3)/5)   + yy + math.floor(yy/4)  - math.floor(yy/100)  + math.floor(yy/400) + 2
  local val9 = math.floor(val8/7)
  local dw = val8-(val9*7) 
 
  if (dw == 0) then
    dw = 7
  end
 
  return dw, days[dw], fullname[dw]
end
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 7
Date Added: 2018-01-09 04:59:34
Last Modified: 2018-01-10 09:54:13

Web Analytics