Ever need to get the upcoming date or dates for something in a flow?
Whether you need next Friday, next weekday, next 15th of the month, next 3rd Tuesday of every month, next last Monday of the month, next Thanksgiving, or anything else, there is very likely a way to automatically get it using this method.
Also includes an example of how to set a flow to delay until the given date & time that you have selected.
Also includes a way to get the number of weekdays / business days between two dates.
Full Flow
The flow starts by getting the current date in the selected local time-zone
It then creates a dates dataset using that current local date with a Select action set to iterate once for every day in the coming 30 years, so range(1, 10958).
{
"Date": "@{AddDays(body('Current_Date_Timezone_Adjusted'), item(), 'd')}",
"DaysFromStartDate": @{item()},
"Year": @{int(AddDays(body('Current_Date_Timezone_Adjusted'), item(), 'yyyy'))},
"DayOfYear": @{dayOfYear(AddDays(body('Current_Date_Timezone_Adjusted'), item()))},
"Month": @{int(AddDays(body('Current_Date_Timezone_Adjusted'), item(), 'MM'))},
"DayOfMonth": @{dayOfMonth(AddDays(body('Current_Date_Timezone_Adjusted'), item()))},
"DayOfWeek": @{dayOfWeek(AddDays(body('Current_Date_Timezone_Adjusted'), item()))},
"WeekOfMonth": @{add(1,div(sub(dayOfMonth(AddDays(body('Current_Date_Timezone_Adjusted'), item())),1),7))},
"LastDayOfMonth": @{dayOfMonth(AddDays(startOfMonth(addToTime(AddDays(body('Current_Date_Timezone_Adjusted'), item(), 'd'), 1, 'Month')), -1))}
}
Example snippet of dataset JSON generated
[
{
"Date": "1/31/2024",
"DaysFromStartDate": 0,
"Year": 2024,
"DayOfYear": 31,
"Month": 1,
"DayOfMonth": 31,
"DayOfWeek": 3,
"WeekOfMonth": 5
"LastDayOfMonth": 31
},
{
"Date": "2/1/2024",
"DaysFromStartDate": 1,
"Year": 2024,
"DayOfYear": 32,
"Month": 2,
"DayOfMonth": 1,
"DayOfWeek": 4,
"WeekOfMonth": 1
"LastDayOfMonth": 29
},
{
"Date": "2/2/2024",
"DaysFromStartDate": 2,
"Year": 2024,
"DayOfYear": 33,
"Month": 2,
"DayOfMonth": 2,
"DayOfWeek": 5,
"WeekOfMonth": 1
"LastDayOfMonth": 29
},
{
"Date": "2/3/2024",
"DaysFromStartDate": 3,
"Year": 2024,
"DayOfYear": 34,
"Month": 2,
"DayOfMonth": 3,
"DayOfWeek": 6,
"WeekOfMonth": 1
"LastDayOfMonth": 29
} ...
...
...
...
{
"Date": "1/30/2054",
"DaysFromStartDate": 10957,
"Year": 2054,
"DayOfYear": 30,
"Month": 1,
"DayOfMonth": 30,
"DayOfWeek": 5,
"WeekOfMonth": 5
"LastDayOfMonth": 31
}
]
Then in every example it uses a Filter array action to filter down to the desired date or dates.
For example to get the next Friday the Filter array action filters to every date with a DayOfWeek of 5. Then the following Compose has the expression to get the Date value of the 1st item in the Filter array output array.
And if you wanted to use one of the selected dates and a time to delay the flow, then you could use the Convert time zone action set-up to generate the appropriate UTC time for the Delay until action
Import the example template flow through the legacy import or through the Solution import attachments below.
Or go to this post for the direct copy & paste option available in the classic designer.
Thanks for any feedback,
Please subscribe to my YouTube channel (https://youtube.com/@tylerkolota?si=uEGKko1U8D29CJ86).
And reach out on LinkedIn (https://www.linkedin.com/in/kolota/) if you want to hire me to consult or build more custom Microsoft solutions for you.
Solution Zip Download Link: https://drive.google.com/file/d/1Uaf3jMUokBQj2w_BjtTfkNVKtwrbgXbo/view?usp=sharing