Skip to main content
July 4, 2020
Question

Javascript decimal time to HH:MM

  • July 4, 2020
  • 1 reply
  • 2972 views

Hello

Need help with script, changing decimal time field to hours and minutes . Thanks 

 

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
July 5, 2020

What do you mean by "decimal time", exactly? Do you mean something like 1.5 should become 1:30?

July 5, 2020

Hi 

Yes that is what I mean . What script could I use to change from decimal to hours and minutes. Thanks

try67
Community Expert
Community Expert
July 5, 2020

You can use this code as the custom calculation script of the second field (adjust the name of the first one as needed):

 

var v = Number(this.getField("Text1").valueAsString);
var hours = Math.floor(v);
var minutes = (v-hours)*60;
var minutesString = (minutes<10) ? "0"+minutes : ""+minutes;
event.value = hours + ":" + minutesString;