问题
I'm building a criteria to get all yesterday's created records for a certain domain class. Something like
def c = A.createCriteria().list {
eq(<some operation on dateCreated>, <some operation on 'now'>)
}
Thanks in advance
回答1:
How about
Date today = new Date().clearTime()
Date yesterday = today - 1
def c = A.createCriteria().list {
ge(yesterday)
lt(today)
}
回答2:
See example criteria here: http://www.grails.org/doc/1.3.7/ref/Domain%20Classes/withCriteria.html
def now = new Date()
between('dateCreated', now-1, now)
will get you everything created within 24h of now. Just use standard Java date manipulation to set your now to midnight.
来源:https://stackoverflow.com/questions/8603311/grailss-yesterday-in-criteria