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

Beginning of the next bi-week week

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

AnyBOBW_DT:= 9/6/1992 & ; any beginning of bi-week (or week) date
BOBW_DT:= AnyBOBW_DT + [14 * (1 + #FLOOR {(A_DT - AnyBOBW_DT) / 14})] &
; replace the 14’s with 7’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). 

(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. But adding 1 more bi-week, (1 + #FLOOR ...), gives us the completed bi-weeks between AnyBOY_DT and the beginning of the bi-week after A_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 next bi-week.

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