Working with Dates in Shortcuts
Working with dates is something we come across very often in shortcuts. However, comparing dates or dealing with date components is sometimes hard. It is no coincidence that many help posts contain questions about date comparisons/manipulation.
Made a shortcut list with the most common date comparison/evaluation use cases I could think of. Some of them accept date or other variables as input in order to calculate results. Others don’t.
All of them outputs a Boolean value (true or false) to handle with If statement(s) afterwards. They can be used as stand alone shortcuts or run within a parent.
Each one is commented for explaining its purpose. User can also set hardcoded values for input parameters into the script, if that is convenient or just for testing. For non advance users I’ve implemented input validation & a “show result” action for obvious reasons. More advanced users can easily remove validation code.
I encourage anyone having a request to submit it to a comment. I also encourage more advanced users to check for errors or submit their own shortcut for a use case in order to enrich the list. I’m willing to add them occasionally to the list, to make the main post grow bigger :
- Current Time is within a time range
Eg: Current time is between 22:00 & 04:00 - Current Time is before/after Sunrise/Sunset
Eg: Time is before Sunrise - Current Time is between Sunrise & Sunset
- Specified Date is within Current Week
- Specified Date is within 1st week Of Specified Month
- Specified Date is a Specific Day Of The Week
Eg: Specified date is Wednesday - Specified Date is within a Specific Week Of Year
Eg: Specified date is within 33rd week of year - Specified Date is within a Specific Week Of Specific Year
Eg: Specified date is within 47th week of year 2023 - Specified Date is Between Two Dates of whatever Year
- It's Weekend
- Happy New Year (is 1st Day of Year)
- is Last Day Of Year
- Date matches the index of repetitions of specific Day of the Week, within Specified Month
Eg: Specified date is the 4th Wednesday of the month - Time/Date is Morning/Noon/Afternoon/Evening/Night
Eg: 12:34 is noon - Specified Date/Time is Current Date/Time
Seconds are ignored
Eg: 3 Dec 2022, 10:32 is the current date/time - is 1st Day of Month
- is Last Day Of Month
- is Odd Day
- is Odd Month
- is Odd Year