Level 1

0% to

Level 2

Tip /

to gain points, level up, and earn exciting badges like the new
Mission!

View all

Create time difference between fields

Level 1

I am trying to calculate the difference in minutes between one autocalculated field to another autocalculated field.  Is this even possible?  I have tried many different codes found online but I am unsure how to reference the specific fields.  This is the autocalc code for both fields:

\$.rawValue = Concat(Num2Date(Date(), "M/DD/YY"), " ", Num2Time(Time(), "h:MM"))

Any thoughts?

Thank you!!!

`; Reference to the date/time fieldsvar dateTime1 = Ref(DateTimeField1)var dateTime2 = Ref(DateTimeField2)  ; Extract the dates from the fields formatted values and convert them into numbersvar date1 = Date2Num(Left(dateTime1.formattedValue, At(dateTime1.formattedValue, " ")-1), "M/DD/YY")var date2 = Date2Num(Left(dateTime2.formattedValue, At(dateTime2.formattedValue, " ")-1), "M/DD/YY")  ; Extract the times from the fields formatted values and convert them into numbersvar time1 = Time2Num(Right(dateTime1.formattedValue, At(dateTime1.formattedValue, " ")-4), "H:MM", \$.locale)var time2 = Time2Num(Right(dateTime2.formattedValue, At(dateTime2.formattedValue, " ")-4), "H:MM", \$.locale)  ; Get difference in minutesvar dateMinutes = (date2 - date1) * 1440var timeMinutes = Abs(time2 - time1) / 60000  ; Show result in numeric field. Use display pattern num{z,zzz,zzz,zzz,zz9.88 'Minutes'}\$.rawValue = Sum(timeMinutes, dateMinutes)`