Home > FAQ > Data Manipulation > Date Rounding in Expressions > End of the current ... examples > End of the current bi-week week

End of the current bi-week week

This is the recommended expression for rounding dates to the end of the current bi-week (week):

AnyBOBW_DT:= 9/6/1992 & ; any beginning of bi-week (or week) date
BOBW_DT:= 13 + AnyBOBW_DT + [14 * #FLOOR {(A_DT - AnyBOBW_DT) / 14}] &
; replace the 14’s & 13's with 7’s and 6's to make this expression work for weeks

A_DT may be either a single date (e.g., 7/16/2015, DOH, #DODEC) or an array of dates (e.g., #DATE). 

This expression calculates the beginning of the current bi-week (week) and then adds 13 (7) days to get the end of the current bi-week (week). (A_DT - AnyBOBW_DT) calculates the number of days between A_DT and AnyBOBW_DT, and #FLOOR {(A_DT - AnyBOBW_DT) / 14} determines the number of completed bi-weeks between A_DT and AnyBOBW_DT. Now, turn the number of completed bi-weeks into days (by multiplying by 14, the number of days in a bi-week) and then add the completed bi-week difference in days back to AnyBOY_DT, to get the beginning of the current bi-week. Adding 13 days gets us to the end of the current bi-week.

If you want to round the dates to the beginning of the current week, change all 14's and 13's to 7's and 6's in the recommended expression.