Grails ORM, how to search for a date without time

I am using postrges db. My domain has a date field:

java.util.Date requestedDate; 

I am trying to search by date in the controller:

 eq ("requestedDate", requestedDate) 

This works great, but the problem is that the date and time must be exactly for this. But in the application, the user enters only the date the elements were searched (for example, give me all the requests made in 2014-02-05, and the browser application will add the current time to the request). Thus, the comparison is not performed because the time entered by the user is different from the time when creating the request. I tried 'like' , but it throws an error.

How to compare only part of the date?

+6
source share
2 answers

You can do something like this:

 Date now = new Date() now.clearTime() def results = Meeting.withCriteria { between('date', now, now+1) } 

Thus, it discards the time portion of the current date, and then executes the β€œbetween” query (it just left between midnight and midnight after 24 hours).

+9
source

However, there seems to be no convenient way to implement this. You need a little detour, calculating the beginning of the day and the end of the day and using the operator.

EDIT I ​​just saw that now rcgeorge23 gave you the right example for this.

0
source

All Articles