Date Calculator

A Typed String example to calculate dates ahead of today and before today. Inspired by Typinator’s dayDelta and @peternlewisCalculation macro.

Usage

Type…

today+20d → Date 20 days ahead
today+3w → Date 3 weeks ahead
today+9m → Date 9 months ahead
today-3w → Date 3 weeks ago

You can change the trigger word and customize the date format in the macro.

Related:


Update (2016-10-18 19:42 Z):

Date token now composed of variables (→ date format easier to customize, less switches).
Thanks to @JMichaelTX

Date Calculator.kmmacros (5.0 KB)

4 Likes

This is wonderful, Tom. I have to frequently figure out today + 45 days. This macro saves me a trip to ask Google about it.

Is there a way to edit the output to be in a different format–say 18 October 2016?

@Tom, thanks for sharing this macro -- very useful.

I need to have the date in IOS format: YYYY-MM-DD

Is there an easy way to get this?
(I know how to change all of the ICDDateTime tokens, but there are too many of them)

The ideal solution would be to set the format as a KM Variable at the top of the macro, so each user could use whatever format they like.

1 Like

Change the format in the token for the dacOutput variable (6×):

%ICUDateTimePlus%dacValue%Days%d MMMM yyyy%

See here for more formats.

Have you tried if this works? I don’t think so, but not sure…

This works:

1 Like

LOL, I tried many things, but not with 2×%%% and Process Tokens

Great, thanks!

I have updated the macro. Thanks!

1 Like

Thank you. Much appreciated. :thumbsup:

Please download the updated version. Easier to customize now.

1 Like

Thank you. :slight_smile:

@Tom, again, my thanks and appreciation for sharing a great macro.

I hope you don't mind, but I've made a small enhancement.
I have collapsed all of the original Actions, so you can easily identify the ones I added.

###VER 1.1 2016-10-18 BY: @JMichaelTX

  • ADD Setup Options
    • Modified Trigger to add optional [sS] to trigger Setup
    • Choose Date Format, OR Make Custom Format
    • Choose Output: Typed String OR Clipboard

The trigger I have setup is:
;today[sS]?[+-]\d+[dwm]

which has these changes:

  • Added a ; at the beginning (my style for all text expanders)
  • Added a [SPACE] at the end (again my style)
  • Inserted optional [sS]? so that Setup will be triggered by lower or upper case S (typing the S is optional)
  • The only change that is essential is the last one.

###If you trigger the Setup mode, you will see this:

and if you choose "OTHER":

Of course, you can change the Macro Prompt default values and choices to be whatever you like -- pre-define your favorite date formats.

Whatever choices/format you set will be remembered for the next execution of the macro.


##Macro Library   Date Calculator with Setup Options


####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/d/d75dcead5b3bd93e7f2793045e5264d95406f259.kmmacros">Date Calculator with Setup Options.kmmacros</a> (19 KB)

If anyone finds any issues/bugs, or has suggestions for improvement, please let me know.

---

###ReleaseNotes

TopicTitle:	Date Calculator
Forum:		Keyboard Maestro Discourse, macro

Post by:		@Tom
Post Date:	2016-10-18
Script Lang:	KM Macro
Post URL:	https://forum.keyboardmaestro.com/t/date-calculator/5260?u=jmichaeltx

A Typed String example to calculate dates ahead of today and before today. Inspired by Typinator’s dayDelta1 and @peternlewis’ Calculation macro1.

Usage

Type…

today+20d → Date 20 days ahead
today+3w → Date 3 weeks ahead
today+9m → Date 9 months ahead
today-3w → Date 3 weeks ago

You can change the trigger word and customize the date format in the macro.

Related:

Date Calculations1
KM Wiki
Date format syntax
Update (2016-10-18 19:42 Z):

Date token now composed of variables (→ date format easier to customize, less switches).
Thanks to @JMichaelTX

Date Calculator.kmmacros (5.0 KB)


1 Like

A bit over my pay grade, but trying to learn.

I use past and future dates all the time, I have it in QuicKeys but would like to get it in KM.

How would I trigger that macro?

I tried typing what it said to type to no avail.

A little 'push' would be appreciated... =)

It depends which macro you have downloaded:

  • For the original macro you have some typed string examples in the first post.
  • @JMichaelTX has added a semicolon in his version (and maybe a space at the end).

Make sure the macro group where the macro is in is activated for your application.

ah NICE`, yeah I was using the modified macro trying to type the original text.
Works nicely, and at least I’m off to a start.
You guys are monsters man! -
very cool, thanx for the nudge~

Sorry for any confusion.
Just to be clear:

  • If You are Using @Tom's Macro, use this trigger:
    • today[+-]\d+[dwm]
    • For example: today+3d
      .
  • If you are using my macro, use this trigger:
    • ;today[sS]?[+-]\d+[dwm][SPACE]
    • where "[SPACE]" is one press of the SpaceBar
    • For example:
      • Normal trigger: ;today+3d[SPACE]
      • Setup Trigger: ;todayS+3d[SPACE]
        • where the "s" can be either lower or upper case "S"
    • IF you prefer @Tom's trigger, or one of your own, it is easily changed.
      • Just be sure to retain the [sS]? in the trigger for my macro.
1 Like

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. =)