Grails's yesterday in criteria

こ雲淡風輕ζ 提交于 2019-12-11 17:14:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!