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

Timesheets Hours Calculation

New Here ,
Oct 07, 2024 Oct 07, 2024

Copy link to clipboard

Copied

Hi there,

just curious if soemone can assist me with this calculation. I'm trying to get a do start time - end time or end time minus startime . which ever works to get a positive number. I thought i had it but i do not. Is this better in Custom or Simplified?

TIA

Annotation 2024-10-07 155032.png

TOPICS
How to , JavaScript , PDF forms

Views

227

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 ,
Oct 07, 2024 Oct 07, 2024

Copy link to clipboard

Copied

What is the format of your time fields?  You can't do it with a simplified notation and it looks like your time field names have spaces in the field names, but it's hard to tell with a screenshot.

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 ,
Oct 07, 2024 Oct 07, 2024

Copy link to clipboard

Copied

The format is in HH:MM

There is a space as well for the name of the field - can readjust it if needed

Get Outlook for iOS<>

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 ,
Oct 07, 2024 Oct 07, 2024

Copy link to clipboard

Copied

The space means you can't use those field names in a simplified field notation, but you need a custom script anyway.  You'll find the answers here:

 

https://community.adobe.com/t5/acrobat-sdk-discussions/how-to-calculate-time-difference-between-2-ti...

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 ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

I tried to go to those forums and links and nothing is showing up

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 ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

Annotation 2024-10-08 091611.png

For better look, i think this is simple but java isn't something i've quite understood yet. Just a start (HH:MM) "SUNStart" and then and end time (HH:MM) "SUNEnd" to equal total deciaml hours on the 3rd row. so i can total for the week. 

This is a time sheet to record hours for staff - they don't need to calculate just add the 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 ,
Oct 07, 2024 Oct 07, 2024

Copy link to clipboard

Copied

Do you want to show total hours as HH:MM or decimal?

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 ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

Decimals preferably 

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 ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

Put this as 'Custom calculation script' in "HOURS WEEK 1" field (remove any other calculation or script you have for those fields) :

 

function timeToMinutes(time) {
 if (!time) return 0;
 var [hours, minutes] = time.split(":").map(Number);
 return hours * 60 + minutes;}

var fields = [
 { start: "SUNStart Time", end: "SUNEnd Time", hours: "SUNHOURS" },
 { start: "MONStart Time", end: "MONEnd Time", hours: "MONHOURS" },
 { start: "TUEStart Time", end: "TUEEnd Time", hours: "TUESHOURS" },
 { start: "WEDStart Time", end: "WEDEnd Time", hours: "WEDHOURS" },
 { start: "THUStart Time", end: "THUEnd Time", hours: "THURSHOURS" },
 { start: "FRIStart Time", end: "FRIEnd Time", hours: "FRIHOURS" },
 { start: "SATStart Time", end: "SATEnd Time", hours: "SATHOURS" }
];

var totalMinutes = 0;

fields.forEach(field => {
 var startVal = this.getField(field.start).valueAsString;
 var endVal = this.getField(field.end).valueAsString;

 if (startVal && endVal) {
  var dayTotalMinutes = timeToMinutes(endVal) - timeToMinutes(startVal);
  dayTotalMinutes = Math.max(dayTotalMinutes, 0);
  totalMinutes += dayTotalMinutes;

  var dayDecimalHours = (dayTotalMinutes / 60).toFixed(1);
  this.getField(field.hours).value = dayDecimalHours;} 
 else {
  this.getField(field.hours).value = "";}});

if (totalMinutes > 0) {
 var totalDecimalHours = (totalMinutes / 60).toFixed(1);
 event.value = totalDecimalHours;} 
else {
 event.value = "";}

 

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 ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

Thank you! This is working but also not and it's now so above my head. It's not calculating in some feilds or adding a runnign total

Annotation 2024-10-08 105829.png

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 ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

LATEST

The issue was hours field names I didn't see correct and assume they are "TUEHOURS" and "THUHOURS" but it was "TUES" and "THURS", anyway I updated script to those names so try now.

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 ,
Oct 08, 2024 Oct 08, 2024

Copy link to clipboard

Copied

Enter the following custom calculation script in the Sunday total hours field and change the field names for the rest:

var start=this.getField("SunStart Time").value;
var end=this.getField("SunEnd Time").value;
if(start=="" || end=="")
{event.value=""}
else
{
var hours=Number(end.split(":")[0])-Number(start.split(":")[0]);
var mins=Number(end.split(":")[1])/60-Number(start.split(":")[1])/60;
event.value=hours+mins;
}

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