0

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?

2 Answers 2

1

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

<?php print $output; ?>

But you need to replace that with

<?php print date('F Y', strtotime($row->node_data_field_date_field_date_value)); ?>

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

0

I ended up solving it this way:

I added a Date field to my content type which only tracked the Year-Month-Day. Then I added a Time field to my content type which only tracked the Time.

In addition to making the grouping easier, it also represented my data is a much better fashion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.