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?
Solved! Go to Solution.
Hi @novice1,
If you will minus 364 days you will get a result that you are interested in.
DateTimeAdd(DateTimeToday(),-364,"days")
Or you can try:
ToString(ToNumber(Left([date field],4))-1) +
Substring([date field],4)
cheers,
mark
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
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
@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.
@novice1 actually just reviewed @RolandSchubert 's solution. Roland's solution works well. You should mark that one as the proper correct solution.
@MarqueeCrew how is this supposed to work? Seems like this is just subtracting one from the year.