Grails query based on Date

877 views Asked by At

imagine I have this domain class:

class Event {

    DateTime startDate
    DateTime endDate
}

I want to find Events that ended in the last 15 to 30 minutes. I would like to have something like:

def now = DateTime.now()

def events= Event.withCriteria {
    ge("endDate".plusMinutes(15), now)
    ge("endDate".plusMinutes(30), now)
}
1

There are 1 answers

0
injecteer On BEST ANSWER

you can do it also with plain Date magic

def events= Event.withCriteria {
  between "endDate", new Date( now.time - 30 * 60 * 1000 ), new Date( now.time - 15 * 60 * 1000 )
}