Home > Enterprise >  How to run Gemfire query for LocalDate?
How to run Gemfire query for LocalDate?

Time:12-08

public class Employee {
 private String name; 
 private LocalDate createdDate; //format yyyy-MM-dd
}

I tried following doesn't work. It says No Data Found. Also how can we do before, between, after queries using the date?

select * from /message where createdDate = to_date('2021-11-29', 'yyyy-MM-dd')

CodePudding user response:

TO_DATE I believe creates a java.util.Date, which I don't think is directly comparable to a LocalDate.

If you are invoking a query from the java API, you could construct a LocalDate and pass it in as a bind parameter. If you do that could should be able to use comparison operators like ">" or "<" to compare the dates, because those will invoke the java compareTo function. For example

queryService.newQuery("select * from /message where createdDate < $1", LocalDate.parse("2021-11-29"))

You might also consider storing a java.util.Date instead of a LocalDate on your object.

  • Related