Skip to main content
Keeemara
Participant
April 17, 2024
Answered

Invoice to convert HH:MM to decimal time

  • April 17, 2024
  • 1 reply
  • 966 views

I am trying to create an Fillable PDF Invoice for my business that I can fill out in Arobat that will auto calculate my total hours in decimal when I add them in the field.

Example: (HH:MM) 3:50 = (decimal time) 3.83

I realized it may need a javascript formula to do this. 

I don't quite know how to set this up, where to put the javascript and etc. Appreciate the help. 

Here is how I have it setup. 

This topic has been closed for replies.
Correct answer Nesa Nurani

To convert time to decimal, you can use this as custom calculation script of 'decimal' field (change field names in script for other fields:

 

function convertTimeToDecimal(timeStr) {
 var parts = timeStr.split(':');
 if (parts.length === 2) {
 var hours = parseInt(parts[0], 10);
 var minutes = parseInt(parts[1], 10);
 return hours + minutes / 60;}
 return 0;
}

var timeInput = this.getField("hh:MM 1").value;
event.value = convertTimeToDecimal(timeInput).toFixed(2);

 

1 reply

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
April 17, 2024

To convert time to decimal, you can use this as custom calculation script of 'decimal' field (change field names in script for other fields:

 

function convertTimeToDecimal(timeStr) {
 var parts = timeStr.split(':');
 if (parts.length === 2) {
 var hours = parseInt(parts[0], 10);
 var minutes = parseInt(parts[1], 10);
 return hours + minutes / 60;}
 return 0;
}

var timeInput = this.getField("hh:MM 1").value;
event.value = convertTimeToDecimal(timeInput).toFixed(2);

 

Keeemara
KeeemaraAuthor
Participant
April 17, 2024

This worked! Thanks so much!

Amal.
Legend
April 26, 2024

Hi @Keeemara

 

We are glad to hear that it worked for you.

 

Marking a reply or response “Correct” will help future users with the same issue quickly identify the correct answer.


~Amal