• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
10

Calculate hours and minutes worked

Explorer ,
Aug 31, 2023 Aug 31, 2023

Copy link to clipboard

Copied

Hi everyone, I'm hoping someone can help me with this.

I'm looking to add up my hours and minutes I've worked into a total box on a job sheet, so in one day if I've spent 3 hours, I enter 3.0, then the next day I worked 1 hour and 55 minutes I will enter 1.55 then if the next day I work 25 minutes I will add 0.25. the total box will sum these up to 4.8, but I'm wanting to keep the hour minute format, so want to to sum it to 5.20.

 

Screenshot 2023-08-31 at 11.18.40 am.png  Screenshot 2023-08-31 at 11.18.53 am.png

Is this possible?

TOPICS
Edit and convert PDFs , General troubleshooting , How to , JavaScript , PDF , PDF forms

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 31, 2023 Aug 31, 2023

Try this as 'Custom calculation script' of "Total" field:

var totalMinutes = 0;

for(var i=1; i<=21; i++){
 var time = this.getField("TimeRow" + i).valueAsString;
  if(time){
   var parts = time.split('.');
   var hours = parseInt(parts[0]);
   var minutes = parts[1] ? parseInt(parts[1]) : 0
   totalMinutes += hours * 60 + minutes;}}

var totalHours = Math.floor(totalMinutes / 60);
var remainingMinutes = totalMinutes % 60;

event.value = totalHours + '.' + (remainingMinutes < 10 ? '0' : '') + re
...

Votes

Translate

Translate
Community Expert ,
Aug 31, 2023 Aug 31, 2023

Copy link to clipboard

Copied

How does you calculate the sum?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 31, 2023 Aug 31, 2023

Copy link to clipboard

Copied

At the moment I'm just using the below in the 'Text Field Properties', where it just adds all the number entered in the selected text fields, in this case, all the 'TimeRow' fields (1-21). 

Screenshot 2023-08-31 at 2.01.42 pm.png

But this just sums them up as standard numbers so for example enterent 1.30 (1 hours 30 mins) and two of the fields sums it to 2.6, which I'm wnating it to show 3.0 as in 3 hours, like it needs to cut off at 0.60 and anything after this i.e 0.70 would be showb as 1.10.

Hope this makes sense.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2023 Aug 31, 2023

Copy link to clipboard

Copied

Use a script for this.

Convert hours and minutes to minutes.

Create the sum of all minutes.

Convert the result in hours and minutes.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 31, 2023 Aug 31, 2023

Copy link to clipboard

Copied

I've searched for scripts and coun't find one that works. And they all seem to include time and well as duration e.g. a column to input time 05:20pm then a duration column 1 hour 20 mins, which isn't what I need, just the duration.

I'm not proficient enough in scripting to add, delete or create my own.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2023 Aug 31, 2023

Copy link to clipboard

Copied

I've developed many similar scripts in the past, and no, it's not a trivial task.

 

If you're interested in hiring a professional to create it for you, feel free to contact me privately by clicking my user-name and then on "Send a Message".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2023 Aug 31, 2023

Copy link to clipboard

Copied

Try this as 'Custom calculation script' of "Total" field:

var totalMinutes = 0;

for(var i=1; i<=21; i++){
 var time = this.getField("TimeRow" + i).valueAsString;
  if(time){
   var parts = time.split('.');
   var hours = parseInt(parts[0]);
   var minutes = parts[1] ? parseInt(parts[1]) : 0
   totalMinutes += hours * 60 + minutes;}}

var totalHours = Math.floor(totalMinutes / 60);
var remainingMinutes = totalMinutes % 60;

event.value = totalHours + '.' + (remainingMinutes < 10 ? '0' : '') + remainingMinutes;

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 01, 2023 Sep 01, 2023

Copy link to clipboard

Copied

Thank you very much, this is spot on.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 05, 2024 Jun 05, 2024

Copy link to clipboard

Copied

LATEST

Hey there! I completely understand your frustration with keeping track of work hours in both hours and minutes. Here are a couple of approaches you can take:

  1. Use a dedicated time tracking tool: Many project management or time tracking apps can handle these calculations automatically. They often offer features like start and stop timers, automatic breaks, and reports that can be helpful for managing your workload.

  2. Manual calculation with conversion: If you prefer a manual approach, you can convert your minutes to decimal hours before adding them. For example, 1 hour and 55 minutes becomes 1.92 hours (1 hour + (55 minutes / 60 minutes)). Then, you can simply add these decimal values to get your total time.

Bonus tip: If you're looking for a quick online tool to convert between time formats or perform basic time calculations, check out Date and Time Calculator It's a free resource that can be handy for situations like this!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines