KM Dates & Times: Notes on Anchors, Intervals, and Translations

I have made a wiki page, but it requires some cleaning up as the forum and the wiki do not entirely agree on formatting codes (I would dearly love to have a Discourse wiki equivalent, but I don't know how long until that might happen, if ever).

Also, there may be some more edits to the post before its settled down. Here are some comments:

This will not give a future time if the DOW is 6 or 7 (ie, Friday or Saturday) - you'll get the past Thursday instead of the future Thursday. To ensure it is positive, you need to add 7 and MOD 7. Like this:

 %ICUDateTimePlus%(7+5-DOW(NOW)) MOD 7%Days%EEE, MMM d, yyyy%

Also, these:

two weeks before Sep 28 2015
    %ICUDateTimeFor%TIME(2015, 9, 28)-(14*24*3600)%EEE, MMM d, yyyy%
Week 20 of 2016
    %ICUDateTimeFor%TIME(2016, 1, 1)+(19*7*24*3600)%EEE, MMM d, yyyy%
Six weeks after Apr 20 2016
    %ICUDateTimeFor%TIME(2016, 4, 20)+(6*7*24*3600)%EEE, MMM d, yyyy%

are more simply done by adding/subtracting in the date column.

%ICUDateTimeFor%TIME(2015, 9, 28-14)%EEE, MMM d, yyyy%
%ICUDateTimeFor%TIME(2016, 1, 1+19*7)%EEE, MMM d, yyyy%
%ICUDateTimeFor%TIME(2016, 4, 20+6*7)%EEE, MMM d, yyyy%

date → string
// intYear → intMonth → intDay → string
%ICUDateTimeFor% TIME(2015, 8, 23) %EEE, MMM d, yyyy%

Keep in mind that TIME is in GMT and the output of ICUDateTimeFor is in local time, so when doing this sort of thing it is best to use midday instead of midnight:

%ICUDateTimeFor% TIME(2015, 8, 23,12,0,0) %EEE, MMM d, yyyy%

which will generally work anywhere since at midday GMT, the entire world (almost) is on the same date. Otherwise, folks with negative GMT offsets (which includes all of the Americas for example) will get the wrong result.

and string → date ?

Keyboard Maestro does not have any inbuilt date string parsing facilities.

2 Likes