Use part of Date field for grouping / sorting in View I'm creating a Schedule page. I created a Schedule Item content type with a Date field which tracks the date and the time. I want to create a View which lists Schedule Items grouped by Date alone.

My data looks like:


2012-07-01 08:00, Event 1
2012-07-01 11:00, Event 2
2012-07-01 11:30, Event 3
2012-07-02 09:00, Event 4
2012-07-02 10:30, Event 5


I would like this to be displayed grouped by the Date portion of that Date/time object so it looks like this:


2012-07-01

08:00, Event 1


11:00, Event 2


11:30, Event 3

2012-07-02

09:00, Event 4


10:30, Event 5



I tried setting the Grouping on my View to use my Date field using a format that only displayed the Year-Month-Day. However, when doing the grouping, it is still grouping on the real value and not the displayed value. Meaning that since each Date/time value is actually different in the time portion, each value is being used as a separate group.

Is there a way I can generate a virtual field which only contains the Date portion of my Date/time field so that I can use it to properly group all items by Day?
Go to your view and add an extra date field, but hide it from display. Use that as the grouping field. Then create a views template for that field. You can look at the template name suggestions, something like views-view-field--field-date-1.tpl.php would work

The default content of that file would be 

&lt;?php print $output; ?&gt;


But you need to replace that with

&lt;?php print date('F Y', strtotime($row-&gt;node_data_field_date_field_date_value)); ?&gt;


Where 'F Y' is the PHP date string format http://php.net/manual/en/function.date.php