Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Determine if end date is after start date

Avatar

Level 2

I have 2 date fields on a form.  When I click the submit button I am trying to make sure the end date is after the start date.

Here is the code I am using:

     var sDate = Date.parse(BackgroundInformation.Background.CheckingDateStart.rawValue);

      var eDate = Date.parse(BackgroundInformation.Background.CheckingDateEnd.rawValue);

      xfa.host.messageBox("Start Date:" + BackgroundInformation.Background.CheckingDateStart.rawValue);

      xfa.host.messageBox("eDate:"+eDate+" sDate:"+sDate);

      if(sDate > eDate)

{
   valid = false;
   fieldName +="Start Date is greater than End Date";
}

The message box shows the start date as 2014-10-30 but sDate is Nan.

I have tried:

     var eDate = new Date(BackgroundInformation.Background.CheckingDateEnd.rawValue);

      var sDate = new Date(BackgroundInformation.Background.CheckingDateStart.rawValue);

and when I display sDate is says "Invalid Date"

Any ideas?

1 Accepted Solution

Avatar

Correct answer by
Level 10

This should work..

     var sDate = BackgroundInformation.Background.CheckingDateStart.value.date.value;

      var eDate = BackgroundInformation.Background.CheckingDateEnd.value.date.value;

      xfa.host.messageBox("eDate:"+eDate+" sDate:"+sDate);

      if(sDate > eDate)

{
   valid = false;
   fieldName +="Start Date is greater than End Date";
}

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

This should work..

     var sDate = BackgroundInformation.Background.CheckingDateStart.value.date.value;

      var eDate = BackgroundInformation.Background.CheckingDateEnd.value.date.value;

      xfa.host.messageBox("eDate:"+eDate+" sDate:"+sDate);

      if(sDate > eDate)

{
   valid = false;
   fieldName +="Start Date is greater than End Date";
}

Avatar

Level 10

I'm assuming that you are using DateTime field in your form..

-Nith

Avatar

Level 10

Hi there, I would suggest you to use FormCalc to do so, it is much more easier to work with date using this language...

By using FormCalc language you can use the following functions:

Date2Num()  & Num2Date()

Hope this help!

Avatar

Level 2

Thank you so much for the answer.  It worked!

Avatar

Level 2

Unfortunately I am using Javascript already.  I don't think you can mix FormCalc and JS.