We're using date ranges for some events in an application. We're finding that when we use the date value and end_value independent of one another then the timezone is incorrect.

For example, inside a view, we're experimenting with our values using twig.

{{ dump(field_open_close_date) }}

Give us this

field_open_close_date' => 
    protected 'string' => string '2020-02-10T20:00:39 - 2020-03-18T14:00:00' (length=41)
   'field_open_close_date__value' => string '2020-02-10T09:00:39' (length=19)
   'field_open_close_date__end_value' => string '2020-03-18T03:00:00' (length=19)

The full date range is correct. Focussing on the end date, 2020-03-18T14:00:00 is correct as we are in +11 right now with daylight saving. But, when looking at the end_value, you can see a +0 date time of 2020-03-18T03:00:00.

I can't seem to (cleanly) fix these in a view and I really don't want to fix them in each view and then in each other location because all other non-views and non-twig examples of this field has the same result. Unless I use the entire range, it wont be correct.

Note that in future I'll just use 2 date fields but we have too much data in the db to change this now.

  • 1
    What is the question? Drupal always stores dates in UTC timezone in the database, also single dates. If you are rendering manually, you also have to provide the timezone manually.
    – Hudri
    Mar 19, 2020 at 6:57
  • Additionally the dump shows a markup object, so it is already a rendered output. To render manually you need the field object.
    – 4uk4
    Mar 19, 2020 at 7:30
  • In Views you could add the field twice, format each for a single date, hide the first field from display and reference it in the second field.
    – 4uk4
    Mar 19, 2020 at 7:36
  • Some misunderstandings I think. The string output contains the date range correctly, but the value and end_value strings contain dates with no timezone modification added. If I want to user value and end_value in a view (rather than the range) I need to modify these.
    – Christian
    Mar 19, 2020 at 7:42
  • 1
    Yes, on PHP level you can access for each of the two field properties a DrupalDateTime object, see drupal.stackexchange.com/questions/252333/…
    – 4uk4
    Mar 19, 2020 at 8:19


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.

Browse other questions tagged or ask your own question.