Add Day(s) to Date

I have a line with text and a date inside the clipboard.
I want to add 7 days to the date that is inside the clipboard.
The problem is that I can use %ICUDateTimePlus% only for the current date, but in the line with text there can be other dates.

For example, this is the line:
This is the line with a date 1983-08-07 #Week
This is the result that I would like to have after running the macro:
This is the line with a date 1983-08-14 #Week

This is a screenshot of the macro that is not working:


This is the error after running the macro:


How to get the result that I would like to have after running the macro?

I don't know enough about the shell to know why your script might be failing, but if you know your dates will always follow this format, you can get the results you're looking for by slightly changing your regex to grab the date numbers, plugging them into variables, and using them in conjunction with the TIME() and "ICUDateTimeFor" token to add seven days to the date in question like this:

Example Macro.kmmacros (3.1 KB)


1 Like

There are much bigger brains in this forum than me so whenever I have a question I search the forum…

In this case I found:

It’s always worth seeing what other users do/have done!

1 Like

If, after reading the other suggestions, you still want to use a shell command, try this:

date -v+1w -j -f "%Y-%m-%d" "$KMVAR_DateOriginal" "+%Y-%m-%d"

The -v+1w tells it to add one week to the date, and the rest sets the date to whatever's in the DateOriginal Keyboard Maestro variable.

I suspect the problem with the command you tried is that it's written for GNU date instead of the BSD version that comes with the Mac. On the Mac, the -d option is used for Daylight Saving Time, not specifying the date to operate on.


Thanks for all the help, it works! Before posting this question I already searched for a solution. But found only topics that gave solutions that are not really what I was looking for. Some solutions were too advanced for me. Because this is a basic question, I hope that it can have value for basic users who are starting with KM.

This macro can be useful if you want to create recurring tasks. I'm using it in an outliner tool like Dynalist, Workflowy, OmniOutliner, Checkvist, Athens Research, Roam Research, or other outliners.

This (screenshot below) works for me, please reply if something can be done better.


When activating the macro it will add 7 days to the date.

It works when there is not a zero at the end of the date:

When there's a zero at the end of the date it does not work properly:

How to fix this, so there's no problem when there's a zero at the end of a date?

OmniOutliner - Date.kmmacros (5.3 KB)

OmniOutliner - Date Macro (v10.0.2)

Your regexes are not capturing the trailing zero. In your example, 2021-10-2 is being sent to the date command, it's returning 2021-10-09. When that gets substituted in for 2021-10-2, the line becomes

#Week #d2021-10-090 this is a test

because the trailing zero wasn't captured and isn't included in the string that gets substituted for.

I think the solution comes from changing the order of the alternatives:


I've left the * off the end of the regex because I don't know what it's for. The macro works for me with this regex in both spots.

Thanks a lot! Right now it works here also.