This code snippet determines the day of the week associated with a date. The class method "test" takes a date as a string in "mm/dd/yyyy" format, and returns an integer corresponding to a day of the week:
Class cartertiernan.getDayfromDate Extends %RegisteredObject
{
classmethod test(date) as %Integer {
Set monthList = $LISTBUILD(0,3,3,6,1,4,6,2,5,0,3,5)
Set centuryList = $LISTBUILD(6,4,2,0)
Set dayList = $LISTBUILD("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
Set day = $PIECE(date,"/",2)
Set monthVal = $LIST(monthList,($PIECE( date,"/",1 )))
Set first2DigsYear = $PIECE( date,"/",3 ) \ 100
Set last2DigsYear = $PIECE( date,"/",3 ) # 100
Set dayOfWeekVal = ( day + monthVal + last2DigsYear + (last2DigsYear\4) + $LIST(centuryList,(first2DigsYear # 4) + 1 ) ) # 7
Quit dayOfWeekVal
}
}
Here's a link to the code on GitHub
(originally posted to CODE by Carter Tiernan, 6/18/14)