Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Formula to find previous Thursday date.

Kaish
8 - Asteroid

Hi All, I am working for a file and I have to update the file daily to send out mails, In the report text I need yesterdays date and previous Thursday date to be displayed, I know how to display the previous day date but I need to find the formula to add previous Thursday date in Formula tool. The date format should be 4th July 2024 or 04 July 2024. if today is thursday 04 July, I need date to be displayed 27th June 2024, and if I will run the file on Friday 05 July, the date should should reflect 04 July which is previous thursday. Can somebody help me with the formula. 

3 REPLIES 3
Raj
16 - Nebula

@Kaish 
find the workflow attached
mark done if solved'

apathetichell
19 - Altair

@Kaish the key here is to figure out the day of the weeky for your day-1 field (we'll call if Field1). You can use the %u option on datetimeformat to get the day of the week and then look to see if it's greater than four or less than four and adjust accordingly. This gives you your days modifier which you can then plug into a datetimeadd tool. Putting this all together we get:

if tonumber(datetimeformat([Field1],"%u"))>=4 then mod(tonumber(datetimeformat([Field1],"%u")),4) else mod(tonumber(datetimeformat([Field1],"%u")),4)+3 endif

 

for your key formula - and then just put use that new column in a datetimeadd like:

datetimeadd([Field1],-[test],"days")

 

Kaish
8 - Asteroid

@Raj Thank you for the solution

Labels