These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Calculating hours between two dates

adobeone2010
Registered: Nov 23 2010
Posts: 27

I have a script that was put together (courtesy of Masi). On occasion, one may work beyond 24 hours, ex; 27:00 hours. So far the script I have will calculate up to 24 hours without a problem. So in my time sheet that I have created I have three fields.
 
Time In
Time Out
Total hours
 
I have two additional fields
 
Date In
Date Out
 
Here is the script I have so far.
 
var vTime1 = timein.rawValue;
var vTime2 = timeout.rawValue;
if (vTime1.length == 4 && vTime2.length == 4) {
var vTime1Minutes = parseInt(vTime1.substring(0, 1))*600 + parseInt(vTime1.substring(1, 2))*60 + parseInt(vTime1.substring(2, 4));
var vTime2Minutes = parseInt(vTime2.substring(0, 1))*600 + parseInt(vTime2.substring(1, 2))*60 + parseInt(vTime2.substring(2, 4));
if (vTime1Minutes > vTime2Minutes)
vTime1 = vTime2Minutes+1440 - vTime1Minutes;
else
vTime1 = vTime2Minutes - vTime1Minutes;
}
var Hours = Math.floor(vTime1/60);
var Minutes = vTime1%60;
if (Hours == 0)
Hours = 24;
if (Hours <= 9)
Hours = "0" + Hours;
if (Minutes < 10)
Minutes = "0" + Minutes;
this.rawValue = Hours + ":" + Minutes;
 
(Above script courtesy of Masi)
  
So what is the script needed to calculate total hours between two different dates? I'm new at this and don't know how to write a script.
 
Cheers,
 
Jim Salo

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

check out this thread.
I posted a solution for the same purpose.

http://acrobatusers.com/forum/forms-livecycle-designer/pm-too-am-negative-value#comment-60234

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

adobeone2010
Registered: Nov 23 2010
Posts: 27
Thanks radzmar for your help but correct me if I'm wrong.....your answer is for FormCalc, mine is in Javascript.
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Right! It's much easier to calculate time in FormCalc than in JavaScript.

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

adobeone2010
Registered: Nov 23 2010
Posts: 27
Maybe easier, I, however have little to no knowledge of either one. So since my script is in Javascript, I'd like to finish it in Javascript. Thanks anyway for your help

Jim Salo
Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
There are functions in FormCalc that do some of the conversion but the Time2Num function still uses milliseconds. In JavaScirpt there are a number of properties of the date object that may make some of the calculations easier like the pair getDate and setDate that allow one to add days and then create a new date object.

// get the current date object
var oNow = new Date();
console.println("Today is: " + oNow);
// get date
var nDate = oNow.getDate();
// advance 60 days
oNow.setDate(nDate + 60);
console.println('In 60 days it will be ' + oNow);

George Kaiser

adobeone2010
Registered: Nov 23 2010
Posts: 27
Dimitri,

Your response was irrelevant and unnecessary. If you would of read my post from the beginning, credit to the original author (Masi) of the script was duly noted. I've never asked for an easy fix, but as I ventured out to have some understanding of this Java language, I've acquired some knowledge. In fact, enough to realize that the script presented before is of Java and not FormCalc, as another poster suggested as a solution (post #1, 2 and 3).

I spent several hundred dollars for Adobe Acrobat Pro 8 and I thought the whole purpose of this forum was to acquire knowledge and help from other users?

Many hours were put in place, with no doubt, by the original author of the script before hand. Many trials and errors were also put in place by myself in order to achieve the desired result. I continue to learn more about Java and FormCalc from both here and abroad.

Dimitri, I suggest before you go out and critique someone's intention of posting, that more effort on your part is taken to examine all the facts. I may not be an expert here in Acrobat but I'm not ignorant to what you are suggesting. Frankly, I'm appalled that a member with an "Expert" title would be so quick as to judge another member.

Finally, I read some of your last posts in response to other members here in this forum and it seems you mostly only suggest a link to read about without providing a real solution. I've had the pleasure of receiving very helpful advice and solutions from other members on this forum. You, Dimitri, do not appear to provide any sort of real solutions but only to criticize and that kind of posting should not be allowed or tolerated in this forum.

Good Day,

Jim Salo


Dimitri
Expert
Registered: Nov 1 2005
Posts: 1389
Hi adobeone2010,

Yes, I do point people to the enormous number of useful resources provided here at AUC for everyone to learn about how to do tasks in Acrobat and LiveCycle Designer. Well over a thousand times last time I looked. The authors and experts here developed those numerous resources in the hopes people would spend time reading and watching and get valuable information from them. In fact, many, many questions asked here in the forums have already been answered in those helpful resources. And even if they have not been answered "exactly" they do offer an understanding of the concepts discussed. There are training videos, tutorials, blogs, articles, on-demand e-seminars, besides the user to user forums.

I have also read your previous posts, i.e.,
"I've searched all the posts for days but kept getting confused and worst, none of them seem to work for me. Can someone write the script for me or explain it...."

Hopefully your persistence in asking people here to write your code for you will work out well, and your project will get completed without you having to have any understanding of it at all. I pointed you to that blog to give you some perspective from those who are trying to help you. Sorry I offended you so much, none taken here.

P.S. Java is not a programming language used in Acrobat at all. I believe you mean JavaScript, as that is the programming language you are attempting to use.


Good luck,

Dimitri
WindJack Solutions
Online Acrobat JavaScript Training & Resource Library
WindJack Solutions
DaveyB
Registered: Dec 10 2010
Posts: 70
@ Dimitri: I took a look at the thread you referred to in post #5 - It is very informative and I believe you were correct in drawing attention to it.

@ adobeone2010 (Jim Salo): Your response to Dimitri was not only un-called for, it was also impolite and bordering on insulting. Please remember that the people helping on these forums are unpaid volunteers and, for the most part are people that have worked their way up through the learning curve to a point where they are able to help others. This does not include a mandate for "helping those that are unwilling to help themselves". The information that was provided to you is a very specific hint, perhaps you should heed it.

DaveyB

LiveCycle Designer 8.0
"Genius is one percent inspiration, ninety-nine percent perspiration." ~~ Thomas Edison
"If at first you don't succeed, get a bigger hammer." ~~ Alan Lewis
"If the conventional doesn't work, try the unconventional" ~~ DaveyB

adobeone2010
Registered: Nov 23 2010
Posts: 27
DaveyB,

I gather reading comprehension is not one of your strong points
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Please remember the Forum Guidelines!

radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

adobeone2010
Registered: Nov 23 2010
Posts: 27
[quote=Dimitri]Hi adobeone2010,


"P.S. Java is not a programming language used in Acrobat at all. I believe you mean JavaScript, as that is the programming language you are attempting to use."

For many years, the use of abbreviations (from Latin brevis, meaning "short") is a way to shorten words to show meaning for the actual word in whole. For ex:

Blvd = Boulevard
Pkwy = Parkway
Assn = Association
Dr. = Doctor
MD = Medical Doctor
LLC = Limited Liability Corporation
Gov = Governor
Java = JavaScript

No offense intended just a clarity to what I meant by "Java" :)


Radzmar,

Thank you for your post #11 "Forum Guidelines" I know your intend was for ALL members to read and adhere to it.