power automate days between two dates

Streamline Date Management: Calculate Power Automate Days Between Two Dates

By Ashley Jackson
AD

Ever found yourself manually calculating days between two dates, wishing for a more efficient way? Microsoft Power Automate, a cloud-based service by Microsoft, can automate this task, streamlining your workflow. Here's a comprehensive guide on how to calculate days between two dates using Power Automate.

Power Automate, previously known as Microsoft Flow, allows users to create automated workflows between apps and services without writing code. By utilizing its expressiveness, we can compute the number of days between two dates, making it useful across various scenarios like tracking project timelines, order lead times, or event planning.

Understanding Date Operations in Power Automate

Power Automate offers a plethora of actions, including those specific to handle dates. It supports a variety of date manipulation functions, making it simple to find the difference between two dates.

AD
the datedif function calculator is displayed in this screenshot from microsoft
the datedif function calculator is displayed in this screenshot from microsoft
How to calculate time between two dates in Years, Months & Days [Excel Formula]
How to calculate time between two dates in Years, Months & Days [Excel Formula]
Calculate working days between two dates in Excel
Calculate working days between two dates in Excel

Before we proceed, ensure that your Power Automate flows have the necessary permissions to read and manipulate dates, and the data sources are compatible for accurate calculations.

Date and Time Functions

Power Automate's Date and Time functions come handy when dealing with dates. To find the difference between two dates, we use the subtractFromTime function, which calculates the difference between two dates or times and returns a duration.

How to use the utcNow() function in Power Automate
How to use the utcNow() function in Power Automate
How I Use Automate Repetitive Tasks with Power Automate for Desktop
How I Use Automate Repetitive Tasks with Power Automate for Desktop
Excel DATEDIF function to get difference between two dates
Excel DATEDIF function to get difference between two dates

The function takes two arguments: the end time / date (when something happens) and the start time / date (when something starts). It then returns the time difference in different units, such as days, hours, minutes, and seconds.

Dynamic Content in Power Automate

One key aspect of Power Automate is its ability to utilize dynamic content from previous actions or triggers. This makes your workflow more versatile and context-aware.

AD

To use dynamic content, click on the Dynamic content button in the action card, and you'll see a list of outputs from the previous action(s). Select the appropriate dates, and you're ready to go.

Calculate Number of Days Between Two Dates in Excel (8 Quick Tricks)
Calculate Number of Days Between Two Dates in Excel (8 Quick Tricks)
Power Automate Send Reminder Emails
Power Automate Send Reminder Emails
Power Query: Date Difference
Power Query: Date Difference
How to Calculate Working Days between Two Dates in Excel (4 Methods) - ExcelDemy
How to Calculate Working Days between Two Dates in Excel (4 Methods) - ExcelDemy
Send Outlook Email with Attachments using Power Automate Desktop
Send Outlook Email with Attachments using Power Automate Desktop
How to Automate Routine Tasks Using Microsoft Power Automate
How to Automate Routine Tasks Using Microsoft Power Automate

Calculating Days Between Two Dates

Now that we understand the fundamentals, let's create a simple flow to calculate the number of days between two dates. We'll use a HTTP trigger to accept two ISO-formatted date strings as parameters.

The HTTP trigger, when invoked, will send a POST request with two body parameters – startDate and endDate. Power Automate will capture these inputs and perform the calculation.

AD

Setting Up the HTTP Trigger

To create an HTTP trigger, follow these steps:

Calculate Working Days between two Dates in Excel: Find Workdays Excluding Holidays & Weekends
Calculate Working Days between two Dates in Excel: Find Workdays Excluding Holidays & Weekends
Usage Of Add Days In Power Automate
Usage Of Add Days In Power Automate
Number of Months Between Two Dates in Excel: 4 Easy Methods - ExcelDemy
Number of Months Between Two Dates in Excel: 4 Easy Methods - ExcelDemy
Power Automate Desktop Introduction - tutorial
Power Automate Desktop Introduction - tutorial
Transform Your Processes with Power Automate
Transform Your Processes with Power Automate
Saving data from Microsoft Forms into Excel using Power Automate (Flow)
Saving data from Microsoft Forms into Excel using Power Automate (Flow)
Saving Time and Increasing Productivity with Power Automate
Saving Time and Increasing Productivity with Power Automate
Power Automate Tutorial for Beginners
Power Automate Tutorial for Beginners
the different types of logos and icons in microsoft's office 365c suite, including
the different types of logos and icons in microsoft's office 365c suite, including
Calculate the Exact Days, Weeks, Months & Years Between Any Two Dates
Calculate the Exact Days, Weeks, Months & Years Between Any Two Dates
Power Automate send email based on form response
Power Automate send email based on form response
Extract Devops Work Item Drop Down Value Using Power Automate
Extract Devops Work Item Drop Down Value Using Power Automate
How to Combine Multiple Excel Files with Power Automate
How to Combine Multiple Excel Files with Power Automate
  1. Sign in to the Power Automate portal.
  2. Click on Create > From blank.
  3. Select HTTP trigger and give your flow a name.
  4. Click on the Consecutive option to transform your trigger into a multi-step workflow.

Using the SubtractFromTime Action

Once the trigger is set up, let's calculate the days between the two dates:

  1. Add a new action – Expression (under the Data Operations category).
  2. In the formula box, enter the following expression: subtractFromTime(variables('endDate'), variables('startDate')).
  3. Click on the Dynamic content for variables('endDate') and variables('startDate'), and select the respective HTTP trigger parameters you set up earlier.

Formatting the Output

By default, the subtractFromTime function returns a duration string. To extract only the number of days, wrap the expression inside another:

AD
split outputs('/d+', subtractFromTime(variables('endDate'), variables('startDate'))).length

This will give you the number of days between the two dates.

To further enhance the output, consider wrapping it in a Compose action followed by Response action to send the result as the HTTP response body. This makes it easy to consume the result from the requesting client.

Power Automate offers a multitude of use cases, and calculating days between two dates is just one of them. Explore its capabilities further to automate tasks, boost productivity, and integrate apps seamlessly.

So, go ahead, automate your world, and make every day count – literally!

AD