In PostGresql, I’m looking for something that simply gets the date of Friday of the previous week, no matter what day I run the program on.
I’ve tried using the DATE_TRUNC() function:
DATE_TRUNC('DAY',NOW()) - INTERVAL '5 DAY' as LAST_CRED_DATE_CYCLE
But with this I have to change the INTERVAL depending on what day I run it. I’ve tried other forms of the DATE_TRUNC and other functions but I just can’t get there. Is there a way to get last Friday’s date no matter what day I run this code?
Thanks.
2
Answers
You can extract last sunday and then remove 2 days to get last friday
fiddle
Date_Trunc() is the function you are loooking for, you just have the wrong field. `Date_Trunc(‘week’, <target_date>) always returns Monday of the week containing the targer_date. From that subtracting 3 (for date) of ‘interval 3 days) will the give the prior Friday. Try