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

Sending
User Review
0 (0 votes)

In this blog, we will check 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.

Problem:
We have a client requirement in which, they want 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 have designed a Power Automate flow that triggers the creation of an account and modification of the same. We have used 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 that 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 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.

Ps: Our favorite Community Summit is back trending with #MySummitNA – Eagerly awaiting to meet our CRM friends in person. Inogic will be at Booth #1334 at the Summit, Gaylord Palms, Orlando, FL from 10th to 13th October 2022. Do block your calendars for 12.15 pm on Oct 12th for our Partner Solution Showcase session Maps for CRM – Maplytics by our CEO at Room Coastal 7 – Convention Center, Level 2. Register now using our Promo Code INOGIC10, and avail of 10% off on your registration!