Convert Duration to Minutes as Integer

Bhadley
Kilo Expert

Hi all,

Wondering if someone had any ideas on how I could make this work. On our Outage table I have the start, end, and duration field with a business rule to calculate the difference between start and end to come up with the duration (normal stuff) but from here what I would like to do is convert this to minutes and copy those minutes into an integer field so that I can use the variable in future calculations (cost, duration, etc).

Played around with a few things so far. Setting attribute of max_unit=minutes on the duration field does break it down to minutes but when trying to pass the variable off to another field it still holds onto the full date and time format of Jan 1970. I always found duration fields to be a bit tricky so wanted to throw this out there and see if anyone has done this in the past or has an idea on how this could be accomplished. Thanks!

1 ACCEPTED SOLUTION

edwin_munoz
Mega Guru

Hello Bhadley,



I think something like this should do it:


var minutes = current.duration / 1000 /60;


current.fieldToStoreMinutes = minutes


View solution in original post

3 REPLIES 3

edwin_munoz
Mega Guru

Hello Bhadley,



I think something like this should do it:


var minutes = current.duration / 1000 /60;


current.fieldToStoreMinutes = minutes


Thanks Edwin,



You got me going in the right direction. I had to format out the duration field a bit more but got it to work using the below;



var duration = current.duration.getGlideObject().getNumericValue()


var durationMinutes = (duration/1000/60);


current.u_duration_minutes = durationMinutes.toFixed();


Thanks Bhadley! I'm glad you got it to work!.