TestProject Forum

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

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

image
image

What add-on are you using to get the year value?

This one Test Automation Addons Library | TestProject, you can get this action straight from the recorder. click on add step manually then search for “get year from …”

clicked on add step manually, searched for “get year from”, nothing is returned

it’s “get the year…” image