Anyone have a formula to obtain the Monday of the ...
# suiteanalytics
k
Anyone have a formula to obtain the Monday of the current week?
k
decode (to_char({today},'D'),'1',{today}+1, '2', {today}, '3', {today}-1,'4', {today}-2,'5', {today}-3, '6', {today}-4,'7', {today} -5)
probably wrong somewhere.
โœ… 1
but should get you on right track
rough idea is turn today into a single digit number where 1 is Sunday or Monday, and then you adjust the date on all the appropriate dates by adding or subtracting to it in order to get the right day for Monday
k
Thanks man, this was extremely helpful. Tweaked it a bit, but this works.
Copy code
CAST_TO_DATE(

DECODE(TO_CHAR(CURRENT_DATE,'D'),
       '1', CURRENT_DATE+1,
       '2', CURRENT_DATE,
       '3', CURRENT_DATE-1,
       '4', CURRENT_DATE-2,
       '5', CURRENT_DATE-3,
       '6', CURRENT_DATE-4,
       '7', CURRENT_DATE -5)
             )
j
if(yesterday == โ€˜Sundayโ€™) return true; else return false;
๐Ÿ™‚
๐Ÿ˜† 1
g
This is smaller:
trunc({today},'DAY')+1
๐Ÿ‘ 2
As Formula (Date)
k
I don't understand why that would work
g
trunc basically truncates the date according to the parameter. The parameter โ€˜DAYโ€™ is confusing, as it truncates the date to the first day of the week, giving you the date of the first day of the week. +1 just adds a day.
๐Ÿค” 1
k
Very nice.
k
Weird, that's great. Helps cut down the enormous formula I'm having to use this criteria in.