Skip to main content
Jul 4, 2020 9:24 PM UTC
Question

Javascript decimal time to HH:MM

Hello

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

 

This topic is closed to new replies. Start a new post to keep the conversation going.

8 replies

try67
Community Expert
Community Expert
Jul 5, 2020 8:10 AM UTC

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

Translate
Jul 5, 2020 9:42 AM UTC

Hi 

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

Translate
try67
Community Expert
Community Expert
Jul 5, 2020 12:27 PM UTC

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;
Translate