Home > FAQ > Data Manipulation > Date Rounding in Expressions > Find the ... examples > Find the last Friday in a month

Find the last Friday in a month

 

; A_DT is a single date or an array of date(s) that you need to
; adjust (e.g., DOB field or #DATE in a transformation expression)

 

EndMth_DT:= #ENDMTH A_DT & ; last day of this mth
DaysToFri:= 5 - #DAYOFWEEK EndMth_DT & ; days from FRI
;    M T W T F  S  S   Day of week
;    1 2 3 4 5  6  7   #DAYOFWEEK
;    4 3 2 1 0 -1 -2   days to Friday

 

; If the last day of the month is Saturday or Sunday, then 
; EndMth + DaysToFri is a Friday (Saturday – 1 day is Friday,
; Sunday – 2 days is Friday), and it’s the last Friday in 
; the current month. If the last day of the month is Monday
; thru Friday, then EndMth + DaysToFri is a Friday, but it’s
; the first Firday of the following month. So, if we subtract
; 7 days, then it’s the last Friday of the current month!

 

EndMth_DT + DaysToFri - (7 * (DaysToFri > 0))