0

I have a Grails Domain that contain two date feild

Date updated
Date created

I want to count number of rows based on updated time with respect to month or hour or year. How can I do that. The methods showed on Internet does not work. I am using grails version 2.4.4.

Update: Example I have a domain that contain four feids

Date Created
Date updated
Long id
Long idx

I want to find how many idx is there in every group when i group by hour. Like there can be 5 in 12h and 6 in 13th hour... so on.. How can i find those.... My comaparison is not fixed. It can be changed to mont or year... In year it will show the number of idx in each year. in month it will show the number of idx in each month..

How can I do this with grails...

Sadlil
  • 1
  • 1
  • Have you tried anything? – Alex K Dec 24 '14 at 04:42
  • Can you give you an example on how you want to count based on month or year? – Shashank Agrawal Dec 24 '14 at 04:49
  • have you tried this? if so, what is the error? http://stackoverflow.com/questions/11024972/how-to-create-criteria-of-group-by-month-of-date-field-grails – Jayson Cheng Dec 24 '14 at 04:51
  • @Jayson yes i tried it said no such property called formula, i tried some more but it did not work. Alex yes I tried manythings, but failed. you may try to provide some answer instead of critisizing. Shashank, I will try to give an example... – Sadlil Dec 24 '14 at 05:49

1 Answers1

0

You can use where detached query:

DomainClass.where { year( updated ) == 2014 }.count()

Similarly, hour(), minute() etc.

Refer WHERE queries for details.

dmahapatro
  • 49,365
  • 7
  • 88
  • 117