Skip to main content
February 5, 2023
Question

How can we get difference between two times ?

  • February 5, 2023
  • 12 replies
  • 0 views

Hi All,

I am having two times saves in 2 variables 

Eg: 1)  2/5/2023 9:00 AM GMT+05:30.  2)   2/5/2023 8:00 PM GMT+05:30

now my ask is what function we should use in order to get the output like output : 11 hrs or in minuts

and also same for dates 

Thank you 

12 replies

yanaln6436
February 5, 2023

After.. decrypting.. your question, I understood that you want to find the difference in time between 2 date/dateTime values, here you go mate; this should help:

a!localVariables(
  local!firstDateTime: now(),
  local!secondDateTime: subtractminutes(subtracthours(now(), 4), 15),
  local!timeDifference: elapsedtime(
    local!secondDateTime,
    local!firstDateTime
  ),
  a!map(
    mintuesDifference: local!timeDifference[5],
    hoursDifference: local!timeDifference[4],
    dateDifference: elapseddays(
      local!secondDateTime,
      local!firstDateTime
    ),
    hoursWithMinutes: time(
      local!timeDifference[4],
      local!timeDifference[5]
    )
  )
)

also consider checking these sections for later requirements on date manipulations. 

February 5, 2023

Thank you for the answer elapseddays() function is not avaliable 

yanaln6436
February 6, 2023

elapsedtime()... my locals' names are self-explanatory, its right there mate, I recommend reading the function description to fully understand it. 

July 19, 2023

Thanks [mention:8419a5a2e69f4f048b1b155b9fc7b8f3:e9ed411860ed4f2ba0265705b8793d05]

mikes0011
Brainy
July 19, 2023

Generally you can just subtract a datetime value from another, it just takes some effort to meaningfully unpack the result.  Here's my quick attempt at something simple:

a!localVariables(
  
  local!time1: datetime(2023, 02, 05, 09, 04),  
  local!time2: datetime(2023, 02, 05, 20, 02),
  
  local!difference: local!time2 - local!time1,
  
  a!map(
    days: tointeger(local!difference),
    hours: hour(local!difference),
    minutes: minute(local!difference),
  )
)