Bizarrely, the GORM where query only accepts the depreciated java.util.Date class.
I was hesitant to write "today - 365" to get last year.
Calendar cal = Calendar.getInstance()
cal.add(Calendar.HOUR, +8)
Calendar cal2 = Calendar.getInstance()
cal2.add(Calendar.YEAR, -1)
Date today = cal.getTime()
Date lastYear = cal2.getTime()
def query = Stats.where{
name.id == 1
period in (lastYear .. today)
}
def results = query.list()
results.each{ println it.period }
Sort the results by the time period with:results.sort{ it.period }
results.each{ println it.period }

0 comments:
Post a Comment