Search code examples
dategemfireoql

How to run Gemfire query for LocalDate?


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')

Solution

  • 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.