How to get difference between Start Date and End Date when they're on 2 different forms
Posted by Jdubs - Dec 23 ’14 at 10:16
On New Form, I calculate the Start Time by startTime = new Date ();
On Edit Form, the end-user chooses a date for End Date, and on that field .change I want to calculate End Time by endTime = new Date();
Question: How do I access the startTime variable that was created on the New Form so that I can do the following on the Edit Form: startTime - endTime?
When these 2 variables are on the same form, I'm able to get the difference and output seconds/hours/days/etc. to my hearts content. But because they're on 2 separate forms, if I re-calculate the startTime it won't pick up the time that was originally on the new form.
I've tried outputting the startTime variable to a SharePoint field and do the following: fd.field('StartTime').value() - endTime, but I come back with a NaN.
Thank you.
-
JdubsMemberMember for: 8 years 5 months 19 days
Would love an answer for this. Here's as close as I've gotten so far:
I get the Date object, convert it to milliseconds, and store it in a variable and a SharePoint field:
New Form
var calcStartDate = new Date();
var cStartTime = calcStartDate.valueOf();
fd.field('calcStartTime').value(cStartTime);
Edit Form
var calcEndDate = new Date();
var cEndTime = calcEndDate.valueOf();
fd.field('calcEndTime').value(cEndTime);
From here, I can calculate the difference using SharePoint, but cannot calculate using Forms Designer/JavaScript.
Doesn't Work
var cTotalTime = cEndTime - cStartTime;
fd.field('calcEndTime').value(cTotalTime);
In SharePoint, the value of the field "calcEndTime" = NaN
Does Work
In SharePoint, I create a calculated field called "tTotalTime" that = [calcEndTime] - [calcStartTime].
When calcEndTime is populated, in SharePoint "tTotalTime" = 1,334,535 (in milliseconds).
What am I doing wrong? Thank you!
-
Dmitry KozlovAdminMember for: 9 years 8 months 16 days
[#1]: Hi,
Could you drop HTML-source of your Edit form with your code in there to [email protected]?
-
JdubsMemberMember for: 8 years 5 months 19 days
Sure! How do I do that?
-
Dmitry KozlovAdminMember for: 9 years 8 months 16 days
[#3]: Just open your customized form in the browser, right-click anywhere on the form, select 'View source' menu item, copy and paste the contents into a text file and send it to [email protected].
-
JdubsMemberMember for: 8 years 5 months 19 days
[#4]:
Done.
I'm still using SharePoint's "calculated" field for this calculation currently.
Thanks so much!
-
Dmitry KozlovAdminMember for: 9 years 8 months 16 days
[#5]:Please, use the following code to calculate difference between two numbers via JavaScript:
var calcStartTime = parseInt(fd.field('calcStartTime').value().replace(/,/g, '')); var calcEndTime = parseInt(fd.field('calcEndTime').value().replace(/,/g, '')); var cTotalTime = cEndTime - cStartTime;