addToTime function(Power Automate Cloud flows)

02/11/2024

Japanese version.

Add (calculate future dates) from the specified  date and time in the specified unit.

The subtractFromTime function is the opposite of the positive and negative of the calculation.

Units can be selected from year, month, week, day, hour, minute, and second.

Units that cannot be calculated with other ADD-based functions are also included.

Spec

addToTime('<timestamp>', <interval>, '<timeUnit>', '<format>')
ArgumentDefaultDescription
timestampRequired fieldSpecify the date and time of the calculation source.
intervalRequired fieldSpecifies the amount by which the date/time is to be moved.
Positive values calculate in the future direction; negative values calculate in the past direction.
timeUnitRequired fieldSpecify the unit of measure for the calculation.
Year,Month,Week,Day,Hour,Minute,Second.
formatyyyy-MM-ddTHH:mm:ss.fffffffKSpecifies the format of the result.

How to use

In most cases, it is used in the "value" when initializing or setting variables of type "string".

Click on the "Expression" tab, addToTime, and the function name and () will be set in the expression field.

Specify arguments.

The first argument is the date, the second is the amount to be moved, and the third is the unit.

When using dynamic content or variables, special specifications are required.

Click on the button, and if the display looks like the following, the setting is complete.

You can change the function by clicking this purple icon.

For example, addToTime('2022-05-15', 1, 'Day'), The result will be May 16, 2022, one day later.

Other formats can be used for calculation as long as they can be recognized as dates.

If you want to change the format of the result, specify the format in the fourth argument.

addToTime('2022/05/15 13:30:45', 1, 'Day', 'yyyyMMddHHmmss')
addToTime('2022-05-15', -1, 'Day')

There is a subtractFromTime to calculate to a past date.

When calculating past dates, whether to use addToTime for negative calculations or subtractFromTime for positive calculations should be unified whenever possible.

Mixing them makes them difficult to understand.

---

Links

Date and time Functions(Power Automate Cloud flows)