- 🇨🇦Canada plousia
It's a bit late, but I had to do this recently and wrote it up on my blog → .
For all the details, you can read the blog post, but this is the basic technique to get the next date from a Smart Date field and display it in your view. You will put this code in your views-view--fields.html.twig template (renaming it for your particular view as needed, e.g. views-view--fields--view-machine-name--display-machine-name.html.twig). You should also be able to use this in the View UI rewritten field output:
// Create new empty array to push future values to {% set future_dates = [] %} // Loop over all date field values; if they are greater than now, push them to the future_dates array. Note that Twig does not have a "push" filter; it's called "merge": {% for key in row._entity.field_event_dates|keys %} {% if row._entity.field_event_dates[key].value > now|date('U') %} {% set future_dates = future_dates|merge([row._entity.field_event_dates[key].value]) %} {% endif %} {% endfor %} // Create variables from the first item of the future_dates array for display. I had to display the date and time separately, hence two variables: {% set next_date = future_dates[0]|date('F d, Y') %} {% set next_time = future_dates[0]|date('h:i A T') %}
You can then put the
{{ next_date }}
and{{ next_time }}
variables wherever you need them in your code. Or just create one variable if you don't need to print the date and time separately.Note that I'm not sure how this will work with Twig caching; your mileage may vary.