0

I'm using views to output a list of nodes with dates. Some node dates have both a start and end date inserted.

If both a start and end date exists, i would like the date to be outputted only taking the day from the start date.

Current: 9 January 2018 - 10 January 2018

Desired: 9 - 10 January 2018

I've tried using a custom field and rewriting the results in views, but this doesn't work. I've also looked in the pre_render and preprocess functions and only see the start date.

Any ideas?

  • Are the start and end dates separate fields, or is this a single daterange field? – mpdonadio Jul 10 '18 at 1:47
  • It's a single date range field – Key Jul 10 '18 at 8:43
0

I have resolved this issue using the compact daterange module, and using one of the committed patches.

https://www.drupal.org/project/daterange_compact

0

There is a possibility to do it without an extra module

  • Add a field in views for the start date and use the custom formatter with j as the custom format. This will output the date without month or year.
  • Add a field for end date and format this date as you wish.
  • Rewrite Results of end date field (or add a custom field) and put the appropriate token replacements

    {{ field_start_date }} - {{ field_end_date }}

Note: this solution cannot handle properly dates spanning 2 or more months

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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