How to write between clause for from & to dates for createCriteria in grails?

孤街醉人 提交于 2020-01-21 10:10:13

问题


I want to fetch results between 2 dates using following code.

def c = TestCase.createCriteria()
resultss = c.list {
    like("testStatus", "Dummy")
    and {
        between("testTime", date1, date2)
    }
    order('testified','desc')
}

Here I want to select From Date and To Date like below

FROM DATE : '2014-11-07 12:14:03'(date1)
TO DATE   : '2015-01-09 08:14:12'(date2)

I tried a lot but no luck to get it run.

Can anybody please tell me how to do that?


回答1:


the and there is odd; first of all and is the default anyway. and if you want to be explicit, then put the statements into the and block:

and {
    like("testStatus", "Dummy")
    between("testTime", date1, date2)
}

or just

like("testStatus", "Dummy")
between("testTime", date1, date2)


来源:https://stackoverflow.com/questions/28604309/how-to-write-between-clause-for-from-to-dates-for-createcriteria-in-grails

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