Moving data from a Time field to a Decimal field

alm
Kilo Explorer

Hi,

 

I'm having trouble moving contents of a Time field type into a decimal field type.

 

Client have so far been using a time field entering HH:MM:SS, but now wants to enter a decimal value.

 

So 1 Hour 30 minutes would then be 1,5.

 

Therefor they have asked for a job to convert all the old entries so that the time field is recalculated to decimal.

 

Looking up the definition of a time field it states that is "Specific time. Stored in the database as an string in milliseconds, but displays in hours, minutes, and seconds."

 

So I tried to simply to move the time field to the decimal field and thought it would then simply be a matter of dividing 60 enough times to get it right.

 

//u_hours Time field type

//u_hours_decimal decimal field type

updateTimeRegistration();

 

function updateTimeRegistration() {

var time = new GlideRecord("u_time_registration");

time.addNotNullQuery('u_hours');

  time.query();

  while(time.next()) {


  time.u_hours_decimal = time.u_hours *1;

 

  time.update();

  }

}


But the result seemed to be way of. So I now have a suspicion that value of a time or data/time field is a number of milliseconds from a certain date.


I was hoping someone could kick me in the right direction as to how to transfer data from a time field to a decimal field.


Regards


Alexander


1 REPLY 1

rowan_staveley
Kilo Explorer

Alexander,



The actual Value rather than displayValue of a glideDuration field is a Value in GlideDateTime format that is the number of hours/mins/secs later than the baseline date: 1970-01-01 00:00:00.



You can use gs.getNumericValue() to get a value (ms I believe) that gives you time since baseline that could be converted into hours