2011-02-27 2 views
0

Grails Joda 날짜 시간 플러그인을 사용합니다. 날짜의 시간 정밀도를 무시하고 하루 동안 모든 레코드를 가져 오려고합니다. 무엇을하는 가장 좋은 방법은?Grails에서 DateTime의 시간을 무시하고 날짜별로 모든 레코드를 가져옵니다.

도움 주셔서 감사합니다.

+0

GORM을 사용하여 데이터베이스에서 이러한 레코드를 가져오고 있습니까? –

+0

예 메신저를 사용하여 메신저 –

답변

2
class Record { 
    DateTime dateField 

    def getAllRecordsForOneDay(aDay = new DateTime()) { 
    def localDate = new LocalDate(aDay); 
    Record.findAllDateFieldBetween(localDate.toDateTimeAtStartOfDay(), localDate.plusDays(1).toDateTimeAtStartOfDay()) 
    //Or with criteria 
    Record.withCriteria { 
     between 'dateField', localDate.toDateTimeAtStartOfDay(), localDate.plusDays(1).toDateTimeAtStartOfDay() 
    } 

    } 

} 
+0

localDate.toDateTimeAtStartOfDay() 및 localDate.toDateTimeAtMidnight() 둘 다 동일한 결과를 반환하므로 쿼리에서 아무 것도 반환하지 않습니다. ( –

+0

ok. 따라서 localDate.plusDays (1)로 답변을 업데이트했습니다. – fabien7474

관련 문제