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

End of the current semi-month

This is the recommended expression for rounding dates to the end of the current semi-month:

EOSM1_DT:= (#IF 14 >= #DAY A_DT
            #THEN 14 + #BEGMTH A_DT
            #ELSE #NEXTBEGMTH A_DT
            #ENDIF) - 1 &

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 rounds the date to the beginning of the next semi-month, and then subtracts 1 day. If the date is before the middle of the month (14 >= #DAY A_DT), then we we want to round the date to the middle of the current month (14 + #BEGMTH A_DT). Otherwise, round the date to the beginning of the next month (#NEXTBEGMTH A_DT). Now, subtract 1 day to the get the end of the current semi-month.

If you want the 15th to be the end of the semi-month (instead of the 14th), then change 14 to 15 in the above expression.