Insert date based on user-defined week number

I'm supporting with documentation weekly events that occur on Wednesdays starting on 8/26 with some dates excluded for holidays.

What's a way that I could paste these dates by referencing the week number relative to the starting date? For instance, when I receive something from a colleague who wants to add to week 13, I want KM to tell me which Wednesday date that was, and if further requested, format the date as YYYY.MM.DD ready to paste.

Date Week #
8/26/20 Week 1
9/2/20 Week 2
9/9/20 Week 3
9/16/20 Week 4
9/23/20 Week 5
9/30/20 Week 6
10/14/20 Week 7
10/21/20 Week 8
10/28/20 Week 9
11/4/20 Week 10
11/11/20 Week 11
11/18/20 Week 12
12/2/20 Week 13
12/9/20 Week 14
1/13/21 Week 15
1/20/21 Week 16
1/27/21 Week 17
2/3/21 Week 18
2/10/21 Week 19
2/17/21 Week 20
2/24/21 Week 21
3/3/21 Week 22
3/17/21 Week 23
3/24/21 Week 24
3/31/21 Week 25
4/7/21 Week 26
4/14/21 Week 27
4/21/21 Week 28
4/28/21 Week 29
5/5/21 Week 30

Unless there's an algorithmic way to determine which weeks you're going to skip (my guess is "no," since you didn't provide one) I would say the easiest macro to write and maintain is one that defines a text variable with lines that contain all the "legal" Wednesdays in the format you want.

It then plucks the one you want from that list based on a number you give it. Because I couldn't find a function or action to extract a particular line from text, I wrote a Perl one-liner to convert the lines shown above into a JSON array. Then I was able to use JSONValue to get the date with the given index.

Here's the macro. It includes only the first six weeks of the list you gave, but it's easy to add the rest and then update it periodically as time goes on. Also, it just pastes the date because I wasn't sure what else you wanted to do.

Date by Week Number.kmmacros (4.9 KB)

1 Like

Thank you so much! I didn't make it clear, but the list in my original post was all the Wednesdays I need, with the holidays already removed. So I added the remaining dates into your macro and it works like a charm.

Love this forum, this software, and the users of both.

1 Like