# Date calculator challenge

I use ;tu to give me next Tuesday’s date, 17-03-21. The following 1-liner works except when today is Tuesday, and then this macro returns THIS Tuesday instead of NEXT Tuesday.

%ICUDateTimePlus%(7+3-DOW(NOW)) MOD 7%Days%yy-MM-dd%

Of course I have similar macros for the other days of the week.

I have a longer macro that corrects for this problem, but I want a simple and elegant 1-line macro to do it. I am getting too old to sort this out. Can anyone solve the problem?

How about a simple IF test:

If you really want to, you can turn this into one statement/action.
I'll leave that as an exercise for the reader.

If N is a number from 0-6, and you want 7,1-6, then use:

``````((N + 6) MOD 7) + 1
``````

So you have N is (7+3-DOW(NOW)) MOD 7

So you want:

`````` ((((7+3-DOW(NOW)) MOD 7) + 6) MOD 7) + 1
``````

which, if my math degree still holds up, simplifies to:

`` ((6+7+3-DOW(NOW)) MOD 7) + 1``

They actually gave you a math degree!?!?

Last I knew, 6+7+3 would simplify to, er a, OK, got 10 fingers and 10 toes, so it would be, let's see, on yeah, 16. LOL

Sorry, Peter, but you set yourself up for that one with the "simplifies" term.

I can joke about math, because while I aced all of my math classes (aerospace with math minor) back in the day, now I can barely count on two hands, much less the incredible trig substitutions in diff. eq. I once was known for. So, speaking of LOL, that would be you watching me.

I did the if statement method, but was looking for something simpler and “strictly” mathematical, which is what Peter gave me. Thanks for that.

I also have a math degree and routinely solved partial differential equations on IBM 360-generation machines. I claim, tongue partially in cheek, that if I’d only been a bit smarter, I could have discovered the butterfly effect, because I experienced it, but attributed it to either my flawed skills, or the computer’s flawed capacities. Of course, I was about 5 years too late, but what is 5 years?

To generalize to all days, I think the equation is

((13+N-DOW(NOW)) MOD 7) + 1

which works perfectly, at least on Thursday. Thanks, guys, quick response!