How to add and subtract date using subtractFromTime() and addToTime() functions within Power Automate

By | September 30, 2022

In this blog, let us see how we can add and subtract an ‘x’ time unit such as second, minute, hour, day, week, month, and year into and from the existing date.

Requirement:
We recently had a client requirement in which, the client wanted to calculate the next follow-up date for the current customer. This operation is performed when a new Customer (Account) is to be added to CRM and customer details are to be updated in the CRM.

Solution:
To achieve the above user requirement we designed a Power Automate flow that triggers the creation and modification of an account. We used the addToTime() function for this. On firing this flow, the CreatedOn field of the account is read and the addToTime() function gets applied to it. The output value gets updated in the “Next follow up” file which is filled on the account form. Please find the below syntax for the function:

Syntax:

addToTime(DATE_TIME,INTERVAL,TIME_UNIT,OUTPUT_DATE_FORMAT)

Where,

  1. DATE_TIME_VALUE: It states the Date Time value in which the time is to be added
  2. INTERVAL_TIME: It represents the numeric number that defines how many seconds, minutes, hours, days, weeks, months, and years are to be added to the date
  3. TIME_UNIT: This defines which time unit (second, minute, hour, day, week, month, year) needs to be added to the existing date time
  4. OUTPUT_DATE_FORMAT: It shows the string date format in which the output of the date is to be seen

Example:

Here, we can notice that one week is created on the field of Account entity and displayed on the account entity form:

addToTime(triggerOutputs()?[‘body/createdon’],1,’Week’, ‘dd-MM-yyyy’)

Output:

Also, we can subtract second, minute, hour, day, week, month, and year from the existing date-time using the following-

subtractFromTime(triggerOutputs()?[‘body/createdon’],1,’Week’, ‘dd-MM-yyyy’)

On firing the Power Automate flow we get the following result-

Conclusion:

Thus, in this manner, using subtractFromTime() and addToTime we can add or subtract second, minute, hour, day, week, month, or year time intervals from the existing date.

Accelerate Your Project Timeline with Our Dedicated Development Team!

Facing Dynamics 365 CRM or Power Platform resource constraints? Whether you need dedicated FTE developers, outsourced development, or offshore development centre support, we’re here to propel your project forward. Leverage our Microsoft Technologies expertise to meet deadlines and surpass expectations. Reach out to us at crm@inogic.com for project success.