Date Calculation from a specific date

I’m trying to create a list of dates with the format MMM-dd-yyyy-EEE, which should spit out Jul-06-2016-Wed.

The idea is to end up with a list of dates thus:
Jan-1-2017-Sun Jan-2-2017-Mon Jan-3-2017-Tue ... Dec-29-2017-Fri Dec-30-2017-Sat Dec-31-2017-Sun

However, I’d like to start on 01/01/2017.

I was thinking of using the time plus feature to keep adding days ie:
%ICUDateTimePlus%1%Days%MMM-dd-yyyy-EEE%
%ICUDateTimePlus%2%Days%MMM-dd-yyyy-EEE%
%ICUDateTimePlus%3%Days%MMM-dd-yyyy-EEE%
...

What I’m struggling to do is set the starting date to 01/01/2017.

I’ve set a variable to text called "YearStart" using "%ICUDateTimeFor%TIME(2017, 1, 1,12,0,0) %MMM-dd-yyyy-EEE%"

I can’t seem to figure out how to use this with time plus.

Any ideas?

Oh, if I’m going at this the wrong way please lead me in the right direction, I’m new to this.

See if these macros offer any guidance:

###Date/Time

Also See:

Many thanks, but they don’t get me any further.

I’m missing the ability to either calculate how many days from today to 01/01/2017 and add that to the ICUDateTimePlus or set the ICUDateTimePlus to 01/01/2017.

Sorry, I thought the Date Calculations link was to this topic. It should help:

I was just reading through when you posted, many thanks.

Still doesn’t solve my issue.

I can hard code the dates, but then I have to do all of them by hand which defeats the object of KM.

I really need to be able to set the date to a specific date and then be able to apply a calculation that will add one day and print the result and then repeat so I can print from 01/01/2017 to 31/12/2017.

Sometimes it takes a little digging and interpretation.
I derived this from the above reference.

This should get you started:

Formula:

%ICUDateTimeFor%TIME(2017, 1, 1 + AddDays + 1)%EEE, MMM d, yyyy%

I'm not sure why the extra + 1 is needed, but it is needed to make the formula work as expected.

Many thanks, but this still requires a hardcode of all the dates.

For my locale I did not need the +1 and to return the 01/01/2017 I needed:

%ICUDateTimeFor%TIME(2017, 1, 0 + AddDays) %MMM-dd-yyyy-EEE%

This returned:
Jan-01-2017-Sun

I then attempted to increment the “AddDays” variable without success.

It seems that this is not possible with my current skills and my allotted time to solve this has now elapsed.

I had hoped it would be simple in KM, but alas not!

I’ll now do this in Numbers in 20 seconds.

You can do it like this, for example:



Date List [draft].kmmacros (3.1 KB)


The result is this:

Many thanks Tom, you're my new hero!

Worked a treat.

I use this to create a calendar in Workflowy. I tweaked it so that I also had a day of the week separator as each day may be used multiple times in Workflowy for different events, meetings etc. So the final KM looked thus:

This will be script I can use each year to create a new calendar and add to as time goes by.

Is there a simple way to get the week info in the output file as well? So that the files would output the following:

Week (W52) 26 Dec - 01 Jan ------------Sunday------------ Jan-01-2017-Sun Week (W01) 02 Jan - 08 Jan ------------Monday------------ Jan-02-2017-Mon ------------Tuesday------------ Jan-03-2017-Tue ------------Wednesday------------ Jan-04-2017-Wed ------------Thursday------------ Jan-05-2017-Thu ------------Friday------------ Jan-06-2017-Fri ------------Saturday------------ Jan-07-2017-Sat ------------Sunday------------ Jan-08-2017-Sun Week (02) 09 Jan - 15 Jan ------------Monday------------ Jan-09-2017-Mon ------------Tuesday------------ Jan-10-2017-Tue ------------Wednesday------------ Jan-11-2017-Wed ------------Thursday------------ Jan-12-2017-Thu ------------Friday------------ Jan-13-2017-Fri ------------Saturday------------ Jan-14-2017-Sat ------------Sunday------------

I know you can also do date calculations in a shell script, using the “date” command. But I don’t know enough about it to do what you’re specifically asking for.

This:


Date List [draft].kmmacros (7.4 KB)


I standardized the variable names a bit, so they are grouped together in the variables inventory. You can also enable the Cleanup group at the end, if you prefer.


Thanks, but it was @JMichaelTX who provided you with the important information.

1 Like

Wow! that truly is epic!

Many thanks @Tom and @JMichaelTX!

Where do you learn these skills?

Here, in this forum. Where else? :wink:

1 Like

Tweaked File: Date List [draft]v3.kmmacros (8.0 KB)

I've tweaked this slightly so that it now outputs:

------------Sunday------------ Jan-01-2017-Sun Week (W01) Mon-02-Jan → Sun-08-Jan ------------Monday------------ Jan-02-2017-Mon ------------Tuesday------------ Jan-03-2017-Tue ------------Wednesday------------ Jan-04-2017-Wed ------------Thursday------------ Jan-05-2017-Thu ------------Friday------------ Jan-06-2017-Fri ------------Saturday------------ Jan-07-2017-Sat ------------Sunday------------ Jan-08-2017-Sun Week (W02) Mon-09-Jan → Sun-15-Jan ------------Monday------------ Jan-09-2017-Mon ------------Tuesday------------ Jan-10-2017-Tue ------------Wednesday------------ ...

Great! I think you learned something in this forum, too :slight_smile:

1 Like

You may want to adjust the use of the TIME() function (per @peternlewis' post here) to include a noon time:

For example (you will need to adjust for your macro):
%ICUDateTimeFor%TIME(2017, 1, 1 , 12, 0, 0)%EEE, MMM d, yyyy%

This will ensure it works for any time zone.

Also See:
Dates and Times [Keyboard Maestro Wiki]

1 Like