Search code examples
javadategroovydate-comparison

How can i compare a int value to multiple string values. so it works on a database. Failed to transform value


Currently I am using an if statement in a Groovy function to see compare it and it dosen't work.

if ((StartDate<=${Day}) && (${Day}<=EndDate))
   return 1
else
  return 0

So guys or girls can u help me out and type a code how to do it using Java? Or fix this code, because I am out of ideas.

I am getting the error:

Failed to transform value 10-08-2018 of column StartDate in function Func2: Failed to convert value 10-08-2018 in column StartDate to type class java.lang.Short


Solution

  • I think you want to compare date elements. You can split a complete date instance into month,day and year like this:

    LocalDate date = LocalDate.now();
    int day = date.getDayOfMonth();
    int month = date.getMonthValue();
    int year = date.getYear();
    

    Hope this will help to get the condition right.