0

In Drupal 7 Views Date/Time field, is there a way to generate multiple timezone values from a single event date, with start and end values?

For example, if an event is entered into the start/end Time fields with 4:00pm to 5:30pm (using PHP date format "g:ia"), is there any way to decrease or increase the rendered values to reflect different time zones, as in "4:00pm to 5:30pm EST / 1:00pm to 2:30pm PST"?

2 Answers 2

1

Yes, of course Drupal can render your date in what ever other time zone you like, it doesn't depend on which time zone was used to enter the date.

Views allows you to select which time zone to use to display your Date field, you can find it under Field settings.

So if you need to display the same date in a different time zone you can simply add the same Field again, and choose a different time zone in its settings. You can add as many of the same fields as you like and set them to different settings.

If you don't like the styling and want to show all the date fields in one element you can "Exclude from display" all of the date fields, then add a Custom text Field or Rewrite the last date field and enter your own code in order in which you want it.

When Rewriting there is a section you can open that lists available patterns. You can copy tokens for each date from there.

If you want Drupal to print out the time zone of a field and you don't have it in any of the offered Date formats you can create your own new format (under Drupal Regional settings) that shows the time zone. Then adjust all the Field settings to use that Format and you won't have to do it manually in your Rewrite or in the Field Label.

2
  • Another reason to upgrade to Drupal 8! Unfortunately in Drupal 7 that option is not available in the Views date field, but only in the node's, which would mean the content editors would have to re-enter the date/time for every time zone.
    – Molesworth
    Commented Nov 20, 2020 at 17:07
  • Yes, I think you might be right, I don't see that in D7. I guess the closest is to set your Content Type field settings to User time zone and let Drupal calculate it for each user. You can include the time zone info in the date format output so it's clear which time zone is being shown. But yes, D8 or D9 have more options here :)
    – prkos
    Commented Nov 20, 2020 at 23:37
1

I guess that could be done using jQuery (or a separate module that does the same) but to me, the easiest way would be jQuery.

So you load your date/time field a second time in your view, "Rewrite the output of this field" so you can give it a different HTML structure and different classes name e.g.

<div class="timezone2"><span class="gmt-label">GMT </span><span class="myOffsetTimezone">+10:00</span><div>

Here's a link on how you could do that: getTimezoneOffset via javascript
The great thing with "getTimezoneOffset" is that it accounts for daylight savings time as well.

Example of your Views Field: enter image description here

2
  • Thanks – however, the objective is to have the View display both the original date/time set in the node's field as well as the result of calculations for alternative time zones. In Views I created a field to display the data that had been entered (4:00pm to 5:30pm) and another field to add or subtract x hours from those values. In the Rewrite area of the field I was hoping to find a way to act on the token [field_event_date], possibly with jQuery, as you suggested.
    – Molesworth
    Commented Nov 20, 2020 at 17:46
  • @Molesworth yes, correct: "... so you load your date/time field a second time in your view, ..." Now you have 2 fields and you can each rewrite them the way you want. if you need to get the starting value of your [field_event_date] rewrite it to: [field_event_date-value] for the ending value rewrite it to : [field_event_date-value2]
    – BassPlaya
    Commented Nov 21, 2020 at 2:07

Your Answer

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

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