views:

36

answers:

1

Hi,

I have a domain class in my Grails app that looks like this:

class Event {
    Date date
}

I want to write a criteria query that selects events that occurred in a certain month of a certain year, any suggestions?

Thanks, Don

+1  A: 

You could probably just use between:

def firstDayOfMonthInYear, lastDayOfMonthInYear;

/* set the two values using Calendar or some other mechanism */

Event.withCriteria {
    between('date', firstDayOfMonthInYear, lastDayOfMonthInYear)
}

I'm not certain of the inclusivity of between - you may need to adjust your start/end dates if it's not inclusive on both ends.

Rob Hruska