Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

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

Learn more

View all

Sign in to view all badges

Create time difference between fields

Avatar

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!!!

1 Reply

Avatar

Level 10

Well, that's not so easy but not impossible.

I made a sample for you.

; Reference to the date/time fields

var dateTime1 = Ref(DateTimeField1)

var dateTime2 = Ref(DateTimeField2)

 

; Extract the dates from the fields formatted values and convert them into numbers

var 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 numbers

var 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 minutes

var dateMinutes = (date2 - date1) * 1440

var 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)