I was trying to make this macro: 1) type a date (formart: m/d) in a prompt user input 2) find out the date which is one day ahead of the date I just typed in the prompt 3) insert the calculated date to text by pasting.
I now from reading the articles and wiki how to do that based on the current date, yet I'm lost totally in doing that based on a specific date I can type in. I tried to search the forum but didn't find a solution. Can anybody help? Many thanks!
Thank you suliveevil. I've read the articles you kindly attached in your reply. Sadly, I still don't find the exact thing I'm look for: calculate date based on any specific date from my input.
See this Alfred Date Calculator workflow then you will know it's very complicated.
There are leap years、different days in each month and other problems to solve, you need to use a programming language (AppleScript、JavaScript、Lua、Python、Ruby……)to create your own set of scripts to achieve what you wanna get.
If you don't wanna start from scratch,you can search for an online date calculator to do the same thing.
It doesn't have to be. Every date calculator need not be a general purpose calculator that handles every edge case.
Don't give up so easily.
Let's take another look at your requirements and see if we can find a solution for your specific use case.
That should be easy enough.
Actually, I already had a macro that does most of what you want.
I've adjusted it to use your date format. IAC, it should be enough for you to use and adapt to your specific needs.
Let us know if this works for you, or you have further questions about your OP.
UPDATED: 2019-03-01 20:03 GMT-6
Just updated the macro to:
Change output date format to match input format: M/D
Provide a Reusable, Configurable, Action to Calculate Dates
While KM provides extensive handling of dates using the ICU tokens & functions, it is very laborous to write a macro which calculates a new date from a date other than the current date.
The Action in this macro presents an alternative to using KM ICU tokens.
It provides one KM Action, a Shell Script with a Bash date command, to accomplishes this with only 5 lines, and yet is very configurable.
It only requires two inputs, which the macro author can enter as KM Variable Tokens in the Execute Shell Script Action Input area, which are Parameters for the script Standard In (stdin):
Base Date
Adjust by amount (in days, +/-)
By Default, the script uses this data, which can be easily overridden:
Adjust By Units: Days
Date Input Format: M/D/Y
Date Output Format: M/D/Y
Override these by adding Parameters to the Script Input area.
If you don't like the defaults, you can easily change the defaults in the script.
REQUIRES:
KM 7+
macOS 10.10+ (Yosemite)
However, it has been tested ONLY in KM 8.2.2 with macOS 10.12.6
How To Use
As a Demo
Just Trigger this macro.
Enter the Base Date and Offset
Observe Results
As a Reusable Action
Save the Execute Shell Script Action somewhere for easy reuse
(choose one of these:)
Thank you for both your encouragement and macro, Michael! I've already embedded it into my workflow and your macro modified for me is also a great example to build something upon it by my own.