I know the variable code for inserting today's date is
%ICUDateTime%MM/dd/yyyy%
Is there a code to make it insert the closest Monday to the day that this variable is being used?
Meaning, if it was being used today, a Tuesday, it would enter yesterday's date but it was being used on Friday, it would enter the Monday for the following week.
I believe you have to first figure out the number of days forward or backward needed to get to the closest Monday and then use either %ICUDateTimePlus% or %ICUDateTimeMinus%. I used the DOW() function and some modulo (i.e., division remainder) arithmetic to get the offset from the nearest Monday. The value of DOW() and the offset we need for each day of the week is this:
Day of week DOW() Offset
Sun 1 +1
Mon 2 0
Tue 3 -1
Wed 4 -2
Thu 5 -3
Fri 6 +3
Sat 7 +2
Here's a macro that does the offset calculation and presents the nearest Monday in the format given in the question:
I admit the first step is a doozy, but it converts what DOW() returns into a number that's either the offset itself (for Monday through Thursday) or a number that's easy to turn into the offset in the if/then step (for Friday through Sunday).
You could undoubtedly avoid the modulo arithmetic by using a handful of if/thens. Maybe someone else will provide a solution that does it that way.
Well, I left that part out—I didn't want to sound that old.
When I went to graduate school my advisor had an engineering model running on a PDP-11/Fortran IV programmed with a line printer. Since I was charged with improving the model, I told him that first step would be to port the model the department's brand new, shiny Vax-11/780. There I could use the new modern Fortran 77 and a CRT!
At that same university, another professor didn't know how to use anything but punch cards, so he made us use them for his assignments.