Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: ejonesThese types of date calculations are usually interesting and require using the mod() function. This seems to do the job.
if firstExec then {
# Pick a date that is on the day of the week you want
baseDate = date(2014,6,7) # This is a Saturday
}
# calculate the number of days difference between the current date
# and that day of the week
dif = 'Date'.dateSubtract(baseDate).mod(7)
# because somehow mod() often returns the negative valid answer and I want
# the positive one
if dif < 0 then dif = dif + 7
# Calculate the number of days to move forward to the day of the week you want
numDaysToMove = 7 - dif
emit *
#emit dif
#emit numDaysToMove
emit 'Date'.dateAdjust(numDaysToMove,"days") as "Week Ending Date"