Date Calculator

got it, very good, thank you ‘J’

I’d like to be able to put a ‘suffix’ on the date number
ie. 11th, 21st 2nd -

As far as I see this is not a notation supported by ICU Date & Time.

Since the suffix depends on the number, you likely would have to apply regex replacements to the final variable (before inserting it):

  • The numbers 1, 21, 31 must get a “st”
  • The numbers 2, 22 must get a “nd”
  • The numbers 3, 23 myst get a “rd”
  • Anything else probably a “th”
1 Like

understood, not sure how to do that, will poke around,
I was able to do a search and replace and get it to work on one date 'type’
I’ll just have to make a few more search and replace’s to cover all the variables. -
sort of country ‘programming’ but it works. =)

set {day:d} to (current date)
set suffix to "th"
if d is 1 then set suffix to "st"
if d is 2 then set suffix to "nd"
if d is 3 then set suffix to "rd"
if d is 21 then set suffix to "st"
if d is 22 then set suffix to "nd"
if d is 23 then set suffix to "rd"
if d is 31 then set suffix to "st"
if d is 32 then set suffix to "nd"
(d) & (suffix) as string

The above is from a textexpander AppleScript snippet I saved once. Not sure what you need to do to adapt it to your needs, though. Hope it helps.

1 Like

You don’t need 32 in the above - not sure why someone put that in there. :slight_smile:

1 Like

For my uses, I only wanted days in the future and the suffix on the date i.e. 12th, 1st
Only works for the DND_dateformat MMM d, yyyy i.e. Apr 21st, 2017
My coding leaves a bit to be desired but it works.
Posted in case anyone wanted this type of version.
trigger is 3 d's, then 1 or 2 digits then space ( I know that's obvious to most folks, but I wouldn't have known that unless someone told me) :slight_smile:

Date Calculator Plus Days Only and Date Suffix.kmmacros (23.9 KB)

Might you be able to modify this macro to work with ver 8.xx -

There is more than one macro above. To which are you referring?
What exact problem are you experiencing in KM 8.0.3?

Right, the Date Calculator Macro, very top of the post -

when I trigger the macro I get-

%ICUDateTimePlus d%EEEE MMMM d, %

This is probably caused by:

I'm sure @Tom will be along before long to post an update/fix.

Yes, that is the problem, I just can’t find where to adjust that. I was able to in one of my versions of your macros, but not this one.
I Hope Tom (OH TOM!!!) comes along to revise.
Thanx for your time.

This is the action you need to adjust:

dacUnit needs to be set to "Months" instead of just "Mo".

And then you need to add another two copies of that action, and change d to "Days" and w to "Weeks".

2 Likes

Update (2017-10-06, KM8)


This is a KM8 update for the Date Calculator macro from post #1.

I also added an option for a second date format:

You can now define two variables:

  • Date Calculator Format 1
  • Use this for your most used format, for example your local date format. E.g. Oct 6, 2017 for the U.S.
  • Date Calculator Format 2
  • Use this for an alternate date format. E.g. 2017-10-06 (ISO) or Week 40 of 2017, etc.

The 'Date Calculator Format 1' variable will be applied if you type "today…", 'Date Calculator Format 2' will be applied if you type "Today…".

So — out of the box — the macro will do this (example):

Current Date Typed String Result
Oct 6, 2017 today+2w Oct 20, 2017 [Variable 'Date Calculator Format 1' used]
Oct 6, 2017 Today+2w 2017-10-20 [Variable 'Date Calculator Format 2' used]

The macro contains some predefined examples (in the green group) for each of the variables. Enable/disable and customize them according to your needs.


Date Calculator [KM8].kmmacros (39.7 KB)



PS:

If you don't like the "today"/"Today" keyword you can easily adapt it to your language:

For example, if you prefer "heute"/"Heute" as keyword, then simply change the [tT]oday part of the Typed String Trigger to [hH]eute

You can also prefix the Typed String Trigger with any non-letter character, like ; or ,

So, for example ‌ ‌ ;[hH]eute[+-]\d+[dwm] ‌ ‌ would be a valid trigger string.

5 Likes

Thanks for the fix and the date format options.

To help myself remember how to use your macro, I added this Comment:

Anyone who wants this can download this Action from here:
Comment.kmactions (1.9 KB)

Note: When you import an Action, like this one, it is inserted immediately after the currently selected Action in the current macro. So be sure to have Tom's macro in edit mode, with the first Action selected.

1 Like

Thanks for your suggestion.

I've added some examples to the comment in the macro:

Hope it is clearer now :wink:

Just re-download the macro from the above link.

2 Likes

Much better than mine. Thanks Tom.
When you get a chance, would you mind uploading just this one Comment Action? I've already made a number of changes to the macro. :wink:

1 Like

Hey JM, you could just download the updated macro, select the Comment action, hit ⌘C, select the Comment action in your modified macro, hit ⌘V and delete the old Comment action.

But — for your ultimate convenience :wink: — here is the standalone Comment action: Comment.kmactions (25.8 KB)

2 Likes

You're right, of course! I really don't know why I didn't think of that.

You are so kind Tom! Much appreciated!
Maybe others will also like this separate download. :smile:

2 Likes

Might you help with this expansion? I have 3 variables I need expanded

%ICUDateTimePlus%%%Snippet_Date_Digit%%Snippet_Date_Unit%MM/d/yyyy%%%

But I can only get it to this point

%ICUDateTimePlus%1DaysMM/d/yyyy%%