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

Timesheet

Community Beginner ,
Apr 11, 2024 Apr 11, 2024

Copy link to clipboard

Copied

I've been going through everything I can about how to create a script for timesheets but they are  all so confusing.

I need a script to show the hours worked (see below) where I used HH:MM for the time in/time out.

Timesheet.jpg

I really appreciate any help provided!

TOPICS
JavaScript , PDF forms

Views

175

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 , Apr 13, 2024 Apr 13, 2024

There were quite a lot of issues with the code... Use this, instead:

 

function timeConvert(timeIn1, timeOut1) {
    if (timeIn1=="" || timeOut1=="") {
        event.value = "";
    } else {
		var sT = timeIn1.split(":");
		var eT = timeOut1.split(":");
		var t1 = (Number(sT[0]) * 60) + Number(sT[1]);
		var t2 = (Number(eT[0]) * 60) + Number(eT[1]);
		var num = t2-t1;
		var hours = (num / 60);
		var rhours = Math.floor(hours);
		var minutes = (hours - rhours) * 60;
		var rminutes = Math.round(mi
...

Votes

Translate

Translate
Community Expert ,
Apr 12, 2024 Apr 12, 2024

Copy link to clipboard

Copied

There are a LOT of code examples in this forum for this task, but first you need to clearly define it. In the first row, for example, the time span goes over midnight. So does that mean the working period can span multiple days? Can it be longer than 24 hours?

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 Beginner ,
Apr 12, 2024 Apr 12, 2024

Copy link to clipboard

Copied

17:00 to 05:25 would be from 5:00 PM to 5:15 AM (say Friday night to Saturday morning) so that would be 12 hours.  Individual could work up to 16-18 hours but nothing over 24 hours.

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 ,
Apr 12, 2024 Apr 12, 2024

Copy link to clipboard

Copied

Try searching for "time calculation" or "worksheet calculation" and you'll find many threads. Here's one example: https://community.adobe.com/t5/acrobat-discussions/timesheet-difference-time-calculation-timein-time...

 

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 Beginner ,
Apr 13, 2024 Apr 13, 2024

Copy link to clipboard

Copied

I looked at that example before but didn't understand it.  Below is an example of the names of my fields:

TimeIn-TimeOut.png

Using the example you provided, I tried editing it to see if I could make it work for me, however, it did not.  See what I put in Custom Calculation Script:

 

function timeConvert(timein1,timeout1) {
var sT = TimeIn1.split(":");
var eT = TimeOut1.split(":");
var t1 = (Number(sT[0])*60)+Number(sT[1]);
var t2 = (Number(eT[0])*60)+Number(eT[1]);
var hours = (num / 60);
var rhours = Math.floor(hours);
var minutes = (hours - rhours) * 60;
var rminutes = Math.round(minutes)/60;
if(!timein1 || !timeout1)
event.value = "";
else
event.value = rhours + rminutes;}

 

Your assistance is greatly appreciated!

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 ,
Apr 13, 2024 Apr 13, 2024

Copy link to clipboard

Copied

There were quite a lot of issues with the code... Use this, instead:

 

function timeConvert(timeIn1, timeOut1) {
    if (timeIn1=="" || timeOut1=="") {
        event.value = "";
    } else {
		var sT = timeIn1.split(":");
		var eT = timeOut1.split(":");
		var t1 = (Number(sT[0]) * 60) + Number(sT[1]);
		var t2 = (Number(eT[0]) * 60) + Number(eT[1]);
		var num = t2-t1;
		var hours = (num / 60);
		var rhours = Math.floor(hours);
		var minutes = (hours - rhours) * 60;
		var rminutes = Math.round(minutes) / 60;
		var total = (rhours + rminutes);
		if (total<0) total+=24;
        event.value = total.toFixed(2);
	}
}

timeConvert(this.getField("TIMEIN1").valueAsString, this.getField("TIMEOUT1").valueAsString);

 

Also, your initial example is incorrect. From 17:00 to 5:25 it's not 10.25 hours, but 12.42.

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 Beginner ,
Apr 13, 2024 Apr 13, 2024

Copy link to clipboard

Copied

I get the below error when I entered the above script:

Error.jpg

function timeConvert(timeIn1, timeOut1) {
    if (timeIn1=="" || timeOut1=="") {
        event.value = "";
    } else {
		var sT = timeIn1.split(":");
		var eT = timeOut1.split(":");
		var t1 = (Number(sT[0]) * 60) + Number(sT[1]);
		var t2 = (Number(eT[0]) * 60) + Number(eT[1]);
		var num = t2-t1;
		var hours = (num / 60);
		var rhours = Math.floor(hours);
		var minutes = (hours - rhours) * 60;
		var rminutes = Math.round(minutes) / 60;
		var total = (rhours + rminutes);
		if (total<0) total+=24;
        event.value = total.toFixed(2);
	}
}

timeConvert(this.getField("TIMEIN1").valueAsString, this.getField("TIMEOUT1").valueAsString);

 

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 ,
Apr 13, 2024 Apr 13, 2024

Copy link to clipboard

Copied

Works fine for me. See attached.

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 Beginner ,
Apr 13, 2024 Apr 13, 2024

Copy link to clipboard

Copied

LATEST

The error was on my end.

 

Screenshot 2024-04-13 143820.png

Thank  you so much!!!!!!!

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