How to write between clause for from & to dates fo

2019-02-20 13:12发布

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?

标签: grails gorm
1条回答
太酷不给撩
2楼-- · 2019-02-20 13:59

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)
查看更多
登录 后发表回答