I am working on a D8 instance and i would like to have 2 dates which are in different fields to be displayed at once when the month is the same i.e. : 21-22 december instead of 21 december 22 december.

What is the best way to do that ?

  • When/where are you trying to do this? In the node view itself, when saving the node, or somewhere else?
    – Greenstack
    Sep 28, 2016 at 22:21

2 Answers 2


This isn't a direct answer to your question, but is probably the best option to move forward.

Drupal 8.2.0 (due 2016/10/05) will include the new datetime_range module, which provides date ranges in a single field.

I would wait until this is available, and then migrate your two datetime fields into a single daterange fields (one to the start value and the other to the end value).

Then, I would make a custom formatter for daterange fields that implements your logic to combine month/year when they are the same for start and end.

You can then configure your various vide modes to use this new formatter.


Add a hook_preprocess_node function to your theme to check if both dates are in the same month. If yes then the function should hide one date and alter the display of the other to display the range. Here is an example of it.

Alternatively, for views you can use pre_render to alter fields conditionally.

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.