How to get difference between Start Date and End Date when they're on 2 different forms

rss

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.

  • Jdubs
    Member
    Member for: 6 years 10 months 9 days
    #1 by Jdubs Dec 23 ’14 at 03:53

    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 Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 1 month 6 days
    #2 by Dmitry Kozlov Dec 24 ’14 at 03:42

    [#1]: Hi,

    Could you drop HTML-source of your Edit form with your code in there to [email protected]?

  • Jdubs
    Member
    Member for: 6 years 10 months 9 days
    #3 by Jdubs Dec 26 ’14 at 03:50

    Sure!  How do I do that?

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 1 month 6 days
    #4 by Dmitry Kozlov Dec 29 ’14 at 04:21

    [#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]

  • Jdubs
    Member
    Member for: 6 years 10 months 9 days
    #5 by Jdubs Dec 29 ’14 at 10:23

    [#4]:

    Done.

    I'm still using SharePoint's "calculated" field for this calculation currently.

     

    Thanks so much!

  • Dmitry Kozlov
    Dmitry Kozlov
    Admin
    Member for: 8 years 1 month 6 days
    #6 by Dmitry Kozlov Dec 30 ’14 at 07:50

    [#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;
    
Displaying 1 to 6 of 6 messages