Skip to main content
tejasn0320
Inspiring
Jan 31, 2024 12:01 PM UTC
Solved

Calculate Months and years form Date difference

Hi

I want to Calculate the date difference in to Months and years 

form given dates 

date1: 15 Jan 2022

date2: 15 Jan 2024

date2-date1

ANS= 2 years

In Appian date difference 

date2-date1 is calculating only days 

730

venkatrea696188
Inspiring
Jan 31, 2024 12:20 PM UTC

Hi [mention:ae9ebe781c79465582221db39f6b7db9:e9ed411860ed4f2ba0265705b8793d05]  

There isn't any OOTB functionality to achieve your requirement , But you can use elapsed Years or elapsed Months functions which are available in "DATE AND TIME UTILITIES". Plugin . Or you can write your own mathematical calculations.

8 replies

harshitb6843
Brainy
Jan 31, 2024 12:08 PM UTC

Divide it by 365?

tointeger(date(2024,1,15)-date(2022,1,15))/365

venkatrea696188
Inspiring
Jan 31, 2024 12:20 PM UTC

Hi [mention:ae9ebe781c79465582221db39f6b7db9:e9ed411860ed4f2ba0265705b8793d05]  

There isn't any OOTB functionality to achieve your requirement , But you can use elapsed Years or elapsed Months functions which are available in "DATE AND TIME UTILITIES". Plugin . Or you can write your own mathematical calculations.

mathieud0001
Genius
Feb 1, 2024 12:45 AM UTC
tejasn0320
Inspiring
Feb 1, 2024 9:27 AM UTC

a!localVariables(
  local!months: elapsedMonths(ri!date2, ri!date1) - ri!gapInMonths,
  if(
    local!months > 12,
    a!localVariables(
      local!month: mod(local!months, 12),
      local!years: quotient(local!months, 12),
      local!years & " Years " & local!month & " Months"
    ),
    local!months & " Months"
  )
)



Thank you for your comments. I utilized date and time utilities and developed the necessary logic.

Known Participant
Jan 23, 2025 10:32 AM UTC

can we get days along with years and months ?

venkatrea696188
Inspiring
Jan 23, 2025 11:48 AM UTC

Yeah Use elapsed time and play with result .Here is a Sample code for you

a!localVariables(
  local!difference:elapsedtime(todatetime(ri!date1),todatetime(ri!date2)),
concat(
  local!difference[1], " Years ",local!difference[2], " difference ", local!difference[3], " Days"
)
)