Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I want to group my nodes by creation day. The timestamp in the database is unixtime, so I can't group by that field -- it puts each node as its own entry (because the timestamps are not the same down to the second). Is there any way to have the query built on a specific format of date (like y-m-d)? I tried using "custom" format in my date field, but it didn't work.
Comments
Comment #1
irakli CreditAttribution: irakli commentedViews formatters kick-in way late in the process - during render, so they won't help you.
Interesting problem, but I will have to think about it. Don't know the answer off of my head.
Thank you.
Comment #2
AntiHero118 CreditAttribution: AntiHero118 commentedI have a similar issue whereby I'm trying to group my nodes by day using the cck date field.
However in my case I am trying to avoid getting the time down to the second. I want to group the nodes by the day they appear in the cck date field, as such:
Monday
-- Node 1
-- Node 2
Tuesday
-- Node 3
-- Node 4
-- Node 5
but when I try to group them using my cck date field now each node appears with it's individual date/time like:
Monday October 5th, 2009 7:00AM - 3:00PM
-- Node 1
Monday October 5th 2009 8:00AM - 12:00PM
-- Node 2
Any potential solutions to this issue? I've been struggling with it.
Cheers
- Jared
Comment #3
leenwebb CreditAttribution: leenwebb commentedI ended up working around this problem by creating *another* date field that only stores as granular as date -- the time is 12:00AM for every entry -- and then I'm grouping by that field. Certainly it's kind of a clunky solution, but it's not bad for my particular case.
Comment #4
marcushenningsen CreditAttribution: marcushenningsen commented@leenwebb
Your solution sounds interesting, could you explain more in detail how you created another field?
Thanks,
Marcus
Comment #5
leenwebb CreditAttribution: leenwebb commentedI don't know what more to say... I created another date field in the same content type, but I told it to be only as granular as y-m-d. That way I can use the new field to group by date, and the original field to hold the fully-granular timestamp.
Comment #6
marcushenningsen CreditAttribution: marcushenningsen commentedRight, I get it, but I also agree that it's a clunky solution.
What we need is a way to group fields based on their rendered value, not the one stored in the data base. I'm, however, not sure this is within the scope of Views Group By. Any comment on this, irakli?
Comment #7
rsevero CreditAttribution: rsevero commentedThe solution proposed by leenwebb at #3 is completely functional. I used it in Statistics Pro going one step further: I changed the field from timestamp to date instead of adding an extra field.
For Views GroupBy I imagined a solution where users would be able to add arbitrary SQL functions around each field to preprocess field data before grouping. I'm not sure it would really work as I did not implement it yet.
It would be a bit clunky but would provide complete flexibility.
Postponing it as a feature request.
Comment #8
stevebab CreditAttribution: stevebab commentedThere are a few situations where granularity can't be adjusted to day, and it would be helpful if there were a workaround for date granularity within ViewsGroupBy:
1) User registrations by date
2) Ubercart orders by date
These are just a few examples where date granularity would be helpful, and adding a CCK field is not really a viable solution.