This formula is self-explanatory. It uses the NOW()
function to output the date of whatever the final weekday of the current month.
IF(
WEEKDAY(DATEADD(DATETIME_PARSE(DATETIME_FORMAT(DATEADD(NOW(), 1, 'month'), 'YYYY-MM') & '-01'), -1, 'days')) = 0,
DATEADD(DATETIME_PARSE(DATETIME_FORMAT(DATEADD(NOW(), 1, 'month'), 'YYYY-MM') & '-01'), -3, 'days'),
IF(
WEEKDAY(DATEADD(DATETIME_PARSE(DATETIME_FORMAT(DATEADD(NOW(), 1, 'month'), 'YYYY-MM') & '-01'), -1, 'days')) = 6,
DATEADD(DATETIME_PARSE(DATETIME_FORMAT(DATEADD(NOW(), 1, 'month'), 'YYYY-MM') & '-01'), -2, 'days'),
DATEADD(DATETIME_PARSE(DATETIME_FORMAT(DATEADD(NOW(), 1, 'month'), 'YYYY-MM') & '-01'), -1, 'days')
)
)
Leave a Reply