0

Now, I just enhance the Java application and control the application form. The function will avoid the user to enter the wrong date. The condition as follow:

Expected result:

Start Date End Date

01-APR-2018 03-APR-2018
04-APR-2018 07-APR-2018

Show the error message: The secord record start date cannot greater than first record end date.

I try to compile the program but no any errors. Then, the function is not work.

public boolean CheckDateRecord(ExceptionGenerator eg, int dateCount, Date date, Date pstartdate, Date penddate, int id)  throws Exception {
            boolean CheckDate = false; 
  for (int i=1;i<=dateCount;i++)
    {
        Date date = hd.getdate( i );
        Date startdate = date.getData(1);   // Get Start Date
        Date enddate = date.getData(2);     // Get End Date     

                if (id != i &&

                           //check the record end date cannot greater than start date condition

            ((startdate.getValue().compareTo(pstartdate.getValue()) > 0 && 
              pstartdate.getValue().compareTo(penddate.getValue()) > 0
              ) ))
        {
            CheckDate = true;
            break;
        }
    }

    return CheckDate;

         }
Ben Lee
  • 1
  • 3
  • 1
    What is `Date.getValue()`? That's not a method on the standard `Date` class. – Bernie May 07 '19 at 05:50
  • Date.getValue() = 02/10/2018 (format: DD/MM/YYYY) – Ben Lee May 07 '19 at 05:56
  • I might miss something due to the awful formatting but `startdate.getValue().compareTo(pstartdate.getValue()) > 0 && pstartdate.getValue().compareTo(penddate.getValue()) > 0` will always be `false` – gapvision May 07 '19 at 06:13
  • Date is not java.util.Date is it? This is some weird custom date class, so you are on your own with that. – rghome May 07 '19 at 07:37

0 Answers0