Alteryx Designer Desktop Discussions

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

date today last year

novice1
8 - Asteroid

I am looking out for a solution, to get the below formula to return date for today last year.

 

For example, date today (Sunday) is 2020-11-15, but date on Sunday last year was 2019-11-17.

 

DateTimeAdd(DateTimeToday(),+2,"days") will provide an output of 17/11/2020

 

Is there a way I can get a this date, but in 2019?

9 REPLIES 9
Emil_Kos
17 - Castor
17 - Castor

Hi @novice1,

 

If you will minus 364 days you will get a result that you are interested in.

 

DateTimeAdd(DateTimeToday(),-364,"days")

MarqueeCrew
20 - Arcturus
20 - Arcturus

Or you can try:

 

ToString(ToNumber(Left([date field],4))-1) +
Substring([date field],4)

 

 cheers,

 

 mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
RolandSchubert
16 - Nebula
16 - Nebula

Hi @novice1 ,

 

are you looking for the date last year or the same weekday? I think, you need an addition "adjustment", i.e. a difference between weekday this year and weekday last year. I've attached a workflow to calculate using a formula tool "step-by-step".

 

Let me know if it works for you.

 

Best,

 

Roland

novice1
8 - Asteroid

Thank you all for your responses.

 

I have existing formula and used simples of solutions

 

DateTimeAdd(DateTimeToday(), -364, "days")

 

It is simple and it works, as I already have quite a few formulas running to calculate Year start and year end for 2020 and 2019, Where year end is always last Friday of previous week.

 

Regards,

Egle

Emil_Kos
17 - Castor
17 - Castor

Hi @novice1,

 

Thank you for marking my post as a solution.

Good luck!

BobR
8 - Asteroid

@novice1   if you implemented this 3 years ago you are about to have some issues, surprised you didn't have those back then. the day of the week last year is not always 364 days behind. sometimes its 363 and there is probably some other weird situations. someone did this in code I've inherited and its now broken. best practice is to always use date functions to figure this stuff out.

I don't have a solution yet, but will post one when I come up with one or find one, but one thing for sure is that @Emil_Kos 's solution will get you in trouble.

BobR
8 - Asteroid

@novice1   actually just reviewed @RolandSchubert 's solution. Roland's solution works well. You should mark that one as the proper correct solution.

BobR
8 - Asteroid

@MarqueeCrew how is this supposed to work? Seems like this is just subtracting one from the year.

novice1
8 - Asteroid

@BobR can you please share solution?

 

I have been using something that looks like this 

 

 

Labels