Dates: Get the day of the week for a specified date/week

Get the day of the week for a specified date/week

You can pass in a date, and a day of week, and this function will return back the date in that week, for that day of week.

This method relies on the date math function references as g_sub_setDate

var myDate = arguments[0] //date to use for first day calc.  Must be Date object
var targetStartDayOfWeek = arguments[1] //set what day you are looking for. 0=Sunday 1=Monday
if(!targetStartDayOfWeek) 
    targetStartDayOfWeek = 1 //default to monday

var weekDay = myDate.getDay() 

if(weekDay == targetStartDayOfWeek) 
{ 
    return myDate 
} 
else 
{ 
    var diff = targetStartDayOfWeek - weekDay 
    return globals.g_sub_setDate(myDate, diff, "+");
}