Calculate the difference between the resloved date and created dated

calculate the difference between the resloved date and created dated in years , months and day format.

eg : 810 days was the result . BUT i need it as 2 years , 2 months and 11 days format as the result .

Written the script in the script field with script runner plugin .

Can anyone help me in code to convert in my required format

Hi @kiranmaigenkolla1

if you have days, you can try to format them to the correct format

‚Äčimport java.time.* 

int totalDays = 810  

Period diff = LocalDate.now().with { now ->
    Period.between(now, now.plusDays(totalDays))
}  

println "$diff.years years, $diff.months months and $diff.days days"

Results: 2 years, 2 months and 18 days

Cheers
Adam

1 Like

Hi @adam.labus ,

Getting the below error after giving the import as well

Hi @kiranmaigenkolla1

add below imports:

import java.time.LocalDate;
import java.time.Period;

Cheers
Adam

Thanks its working