How to get difference between Start Date and End Date when they're on 2 different forms
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.
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.
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!
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 Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
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 support@spform.com.
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Please, use the following code to calculate difference between two numbers via JavaScript:
Code: Select all
var calcStartTime = parseInt(fd.field('calcStartTime').value().replace(/,/g, ''));
var calcEndTime = parseInt(fd.field('calcEndTime').value().replace(/,/g, ''));
var cTotalTime = cEndTime - cStartTime;
-
- Information
-
Who is online
Users browsing this forum: No registered users and 11 guests