TestProject Forum

Convert difference between two date field to Years, Months and Day

How to convert difference between 2 date fields to Year , Months, Days.

For example

Date 1 : 01 - Jan - 2020 Date 2: 20 - Dec - 2021
I want to get the difference as 1 Year 11 Months 20 Days

You can use built in actions (Evaluate Mathematical Expression, Get the year from a DateTime object, Get the month from a DateTime object) to do something like this (example for the year) but you can do the same for day/month as well (the date values can be parameters)
Then you can store is as a sub test with output parameter, and use it as a step whenever you need to extract difference