Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save imjayson/5772046 to your computer and use it in GitHub Desktop.
Save imjayson/5772046 to your computer and use it in GitHub Desktop.
Grails: createCriteria query, group by day, on a single date field (modify for grouping by month, year, hour, minute, seconds)
DOMAIN CLASS (Post):
String timeDay
Date date
static mapping = {
timeDay formula: "FORMATDATETIME(date, 'yyyy-MM-dd')" // h2 sql
//timeMonth formula: "DATE_FORMAT(time, '%Y-%m-%d')" // mysql sql
}
CONTROLLER:
def c = Post.createCriteria()
def charting = c.list {
eq("project", project)
between("date", fromDate.getTime(), toDate.getTime())
projections {
groupProperty('timeDay')
count('date')
}
order("timeDay", "asc")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment