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

TimeSheet Help in Adobe Acrobat PDF as In the Excel

New Here ,
Mar 05, 2022 Mar 05, 2022

Copy link to clipboard

Copied

Hi I am new in this field. I have created a worksheet in EXCEL that calculates total hours worked. It is working both for day time or midnight time. See screenshot.

I want to create the similar workshet in ADOBE Acrobat PDF Form. I have tried many scripts from here but wsn't successful.

Say I have two fields, "Time In" and "Time Out", Kindly help me how I can do this?

Time calculated should be in HH:MM format.

Your help means a lot to me. 

Thans & Regards,

Muasher 

TOPICS
Create PDFs , How to , JavaScript , PDF forms

Views

3.4K

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 , Mar 10, 2022 Mar 10, 2022

Use this code as a doc-level script:

 

function calcTimeDiff(startFieldName, endFieldName) {
	var startField = this.getField(startFieldName);
	var start = startField.valueAsString;
	var endField = this.getField(endFieldName);
	var end = endField.valueAsString;

	if (start=="" || end=="") event.value = "";
	else {
		var startArr = start.split(":") ;
		var finishArr = end.split(":") ;

		var hourDiff = Number(finishArr[0]) - Number(startArr[0]);
		var minDiff = Number(finishArr[1]) - Number(startA
...

Votes

Translate

Translate
Community Expert ,
Mar 07, 2022 Mar 07, 2022

Copy link to clipboard

Copied

Hi,

 

Hopefully, this can help, if you are ablet o get a script running but it is not quite correct, then you can post that script and what is not working for you and we can investigate.

 

https://community.adobe.com/t5/acrobat-discussions/need-help-creating-timesheet-in-adobe-acrobat/td-...

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 ,
Mar 08, 2022 Mar 08, 2022

Copy link to clipboard

Copied

Thanks for the response. But I have applied this code but stil it counts time in decimals. The code I used in Calculate< Custom Calculation Script is,

 

var start = this.getField("Time 3.1").valueAsString;
var finish = this.getField("Time 4.1").valueAsString;

if (start=="" || finish=="") event.value = "";
else {
var startArr = start.split(":") ;
var finishArr = finish.split(":") ;

var hourDiff = finishArr[0] - startArr[0];
var minDiff = Math.floor(((finishArr[1] - startArr[1]) / 60)*100);
if (minDiff<0) {hourDiff--; minDiff += 100;}
if (hourDiff<0) hourDiff+=24;
if (minDiff.toString().length == 1) minDiff = '0' + minDiff;
event.value = hourDiff + "." + minDiff;
}
var nHrs = Math.floor(nElapsed / 60); // whole hours;

// elapsed minutes

var nMins = nElapsed % 60; // remainder minutes;

// format into hours and minutes;

event.value = util.printf("%,101.0f:%,102.0f", nHrs, nMins);

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 ,
Mar 08, 2022 Mar 08, 2022

Copy link to clipboard

Copied

At util.printf you uses the format for floating numbers.

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

What i should use then? Kindly guide me please

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

Use %02d

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

%02D for both?

 

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

%02d for both

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

It is still the same. May be i am doing a mistake. Can you please write this line as I need to add in the form.

event.value = util.printf("%,101.0f:%,102.0f", nHrs, nMins);

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

Replace

"%,101.0f:%,102.0f"

with

"%02d:%02d"

 

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

It's still the same like 1.25 instead of 1:15

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

May be there is something wrong with the calculation.

Check the Javascript console for errors.

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

No error is detected.

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 ,
Mar 09, 2022 Mar 09, 2022

Copy link to clipboard

Copied

Or here is the file with both codes embeded. This may help you. Thanks!

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

I get following error:


ReferenceError: nElapsed is not defined
16:Field:Calculate

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

May be I am not that much good, can you please correct this code in the file attached above and send to me please?

 

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

You must set a value for nElapsed .

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

How?

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

What value want you use for 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
New Here ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

I want a result with HH:MM format. For example if I write Time in 02:00 and Timr Out 04:00 the Total Time should result as 02:00 not 2.0

 

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

Use this code as a doc-level script:

 

function calcTimeDiff(startFieldName, endFieldName) {
	var startField = this.getField(startFieldName);
	var start = startField.valueAsString;
	var endField = this.getField(endFieldName);
	var end = endField.valueAsString;

	if (start=="" || end=="") event.value = "";
	else {
		var startArr = start.split(":") ;
		var finishArr = end.split(":") ;

		var hourDiff = Number(finishArr[0]) - Number(startArr[0]);
		var minDiff = Number(finishArr[1]) - Number(startArr[1]);
		if (minDiff<0) {hourDiff--; minDiff += 60;}
		var minDiffString = minDiff.toString();
		if (minDiffString.length==1) minDiffString = "0" + minDiffString;
		event.value = hourDiff + ":" + minDiffString;
	}
}

 

Then call it like this (for example):

 

calcTimeDiff("D5", "E5");

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

Thank you so much Brother!

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

Can we make it to define day or night like AM or PM?

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

Yes, that's possible, but you keep asking for more and more changes, requiring us to continually change the script you've been given. At a certain point you'll exhaust the good-will you're getting here and will either be asked to learn how to code for yourself, or pay for the help you're getting...

 

This is the last change I will be providing like this:

 

 

function calcTimeDiff2(startFieldName, endFieldName) {
	var startField = this.getField(startFieldName);
	var start = startField.valueAsString;
	var endField = this.getField(endFieldName);
	var end = endField.valueAsString;

	if (start=="" || end=="") event.value = "";
	else {
		var hourInMs = 3600000;
		var startTimeDate = util.scand("mm/dd/yyyy hh:MM tt", "01/01/2022 " + start);
		var endTimeDate = util.scand("mm/dd/yyyy hh:MM tt", "01/01/2022 " + end);
		var timeDiffInHours = (endTimeDate.getTime()-startTimeDate.getTime()) / hourInMs;
		event.value = timeDiffInHours.toFixed(2);
	}
}

calcTimeDiff2("D5", "E5");

 

 

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 ,
Mar 10, 2022 Mar 10, 2022

Copy link to clipboard

Copied

LATEST

Thanks Brother, this was the last change I needed. Thank you so much for help!

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