Day of the week – ShiVa Engine

Day of the week

Function/Handler NAME: GetDayOfWeek ( nYear, nMonth, nDayOfMonth )
TYPE: Function
Code Created By, Date and Version: Shaderman – Apr-27-2014 – 1.0
Code Description: Get the day of week for a date, where nMonth is 0 based! Based on code from http://lua-users.org/wiki/DayOfWeekAndD … nthExample
Function/Handler INPUTS: nYear, nMonth, nDayOfMonth -> The year, month and day to check (i.e. 2014, 4, 27)
Function/Handler OUTPUTS: number value. The number of the weekday, where 0 = Sunday, 1 = Monday…

--------------------------------------------------------------------------------
function SmanDateTime.GetDayOfWeek ( nYear, nMonth, nDayOfMonth )
--------------------------------------------------------------------------------
    --
    -- Based on code from http://lua-users.org/wiki/DayOfWeekAndDaysInMonthExample
    --
    nMonth = nMonth +1
    if ( nMonth == 1 ) then nMonth = 13; nYear = nYear -1  end
    if ( nMonth == 2 ) then nMonth = 14; nYear = nYear -1  end
    local   tmp1 = nDayOfMonth + ( nMonth * 2 ) + math.floor ( ( ( nMonth +1 ) *3) /5 ) + nYear + math.floor ( nYear / 4 ) - math.floor ( nYear / 100) + math.floor ( nYear / 400)+ 2
    local   tmp2 = math.floor ( tmp1 / 7 )
    return  tmp1 - ( tmp2 * 7 ) -1
--------------------------------------------------------------------------------
end
--------------------------------------------------------------------------------



Need more answers?

  • slackBanner