i found excellent example @lserni on calculating last friday of month.
set @date='1962-10-20'; select date_sub(last_day(@date), interval ((weekday(last_day(@date))+7-4))%7 day) friday; +------------+ | friday | +------------+ | 1962-10-26 | +------------+
edit:
based on date supplied, give me next last friday of month (even if date supplied)
based on drew's answer did experimenting , found solution works me.
set @date='2015-09-26'; select case when date_sub(last_day(@date), interval ((weekday(last_day(@date))+7-4))%7 day) > @date date_sub(last_day(@date), interval ((weekday(last_day(@date))+7-4))%7 day) else date_sub(last_day(date_add(@date, interval 1 month)), interval ((weekday(last_day(date_add(@date, interval 1 month)))+7-4))%7 day) end last_friday
Comments
Post a Comment