Date Calculations

I have KM7.

  1. Please could someone very simply explain how I can make a macro - control x -to insert today’s date?

  2. Please could someone very simply explain how to insert a date 45 days from today?

**

Take a look at this post…

**

Cheers,
Bill

Thank you Bill. Unfortunately the images have not come out.

This is what I received:
“Here is one way of doing it. [image] [image] See also Regular Expression Typed String Example for how you could trigger this with a typed string trigger that included the date fields. And if you want to use the date format like “6-2-15”, use the Search Variable action to break the variable into its component parts, like this: [image]”

Any chance you could send it again please.

Best Wishes Mike

Try this... :wink:

Bill

1 Like

Download Date Add.kmmacros example below, once downloaded double click on "Date Add.kmmacros" this will install to Keyboard Maestro

Date Add.kmmacros (5.8 KB)

Cheers,
Bill 

1 Like

I use the following, and a few variations thereof. They are straightforward, work for me, and might serve as templates: it should prove easy to change the resulting date (and time), as well as the format.




I'm sure I picked these up, before customizing them, here or at another helpful KM site. "ICUDate ... ", "NumberDate" and "LongDate" are all KM tokens. These tokens are listed, with many others nearby (all worth knowing), at "Edit ▹ Insert Token ▹ Date".

(@Bill_Mabey — what are the disadvantages compared to your solution? Serious question — I'm still paddling in the macro shallows, and don't see much past the gunwales of my tippy dinghy.)

1 Like

With the Date Add.kmmacros I supplied would do the math for you. Yours is simple which is great also.

I always say Keep it Simple Stupid… (K.I.S.S.)

Bill 

Is there any arithmetic that the OP wants done which the KM token "(ICU)DateTimePlus"* can't do?

*and "(ICU)DateTimeMinus" — though I haven't found a need for it since DateTimePlus accepts negative numbers

Here's another simple macro that seems to meet the OP's need and is robust, afaict:
Insert Date offset by number of days supplied by user.kmmacros (3.1 KB)
Picture:

Your compact "AddDate" macro accepts year and month input for offsetting, which is nice. The point I am trying to confirm is that the ICUDateTimePlus token itself does the math (and units other than days can be specified).

3 Likes

Wow This is good… You are absolutely right, I should have seen this… I like it… :slight_smile:

N.B. I’m keeping this one… :slight_smile:

1 Like

Bill — Thanks for the compliments — and especially for helping me understand KM better.

Cheers.

@penguin — post Q’s for any parts that aren’t clear.

Thank you Bill. Will work on it.

1 Like

Thank you so much for this post. Very easy to follow and have done so. The example you did gives me 21 days in advance. Have I missed something or how do I do 45 days in advance please?

Sorry Kirby. I went from email and not your post above. Trying again.

BRILLIANT. Just changed the 37 (21 days) to 59 (45 days) in your formula and it works. Yippee and thank you so much. Also sorted out how to insert date

Is there a way to use a specific start date instead of the current date? I would like to copy an ISO date to the clipboard and then output the ISO dates of the next 14 days separated by Tabs.

Scope this out:

Here’s a simple way to do this with AppleScript:

------------------------------------------------------------
# ISO-Date of each of 14 days past theDate.
------------------------------------------------------------
set theDate to "5/4/2015 11:30"
set theDate to date theDate

set _collate to {}
repeat 14 times
  set theDate to (theDate + (1 * days))
  set end of _collate to theDate as «class isot» as string
end repeat

set AppleScript's text item delimiters to tab
set the clipboard to _collate as text
------------------------------------------------------------

-Chris

My previous post was a bit unclear. What I meant was, that I need to copy the highlighted iso date of a confluence document to the clipboard, then pres TAB, then paste the ISO date of the following day by typing and repeat that 14 times. Based on your link I tried to use ICUDateTimeFor, but I can’t get it to work:

Set Variable ‘sprintNextDate’ to Text
%ICUDateTimeFor%TIME(%Variable%sprintStartDateYear%, %Variable%sprintStartDateMonth%, %Variable%sprintStartDateDay%+1)%YYYY-MM-dd%

Insert Text by Typing
%Variable%sprintNextDate%

outputs %ICUDateTimeFor%TIME(2015, 10, 09+1)%YYYY-MM-dd% but not the parsed date, I would like to have. Am I missing something here?

Please provide an example of your input.

You don’t paste by typing.

Do you actually need to type the 14 created dates? Or can you paste them?

Are they going back into the confluence document?

Is the original string supposed to be retained or replaced?

-Chris

Manually I’m doing these steps:

  1. I create a new Confluence page based on a custom template which contains a table with 14 columns.
  2. I click into the header cell of the first column and type an certain ISO date (some point in the future).
  3. I press TAB to change the focus to the header cell of the next column.
  4. I type in the ISO date of the following day (based on the date from the previous header cell).
  5. Repeat that until all 14 header cells contain a date.

I would like to speed this up by just entering the first ISO date and then let do KM do the rest.

What app are you doing this in?

Please provide a proper example of the date-format you’re using.

-Chris