0

My SharePoint site is used by people from various time zones. We have a requirement to save and display date value to/from the list using a SPFx solution.

Currently we are using the built-in Date only column for saving the data. But as SharePoint is still saving the date value along with time zone (i.e. UTC), we are having difficulty in maintaining the constant date for users all around the world.

I have gone through some online articles and didn't find anything useful. So, I wonder what should be the best/correct approach for the above scenario? Should I use a single line of text column for my date only fields.

1 Answer 1

1
  1. Choose one timezone to be as the main one.
  2. When generating a new Date, check that the date is being created in the timezone that you chose. For example, if you are in +3 and the timezone is +1, make sure to remove 2 hours from the date you just created (You can get some help from moment.js for this).
  3. Show the user values instead of using .ToLocalDateString(), use the apropiated timezone format, for example: ToLocalDateString("es-ES",{timeZone: "Europe/Madrid"}), so you show the Date/Time as if everyone is in that timezone.

At the end of the day, this is what SP interface / Native is doing. It works as if everyone is in the SiteCollection timezone. If you choose 13:00 in -8, but the timezone is +1. It will be created as if you are in +1, but won't show you an -8 offset, it will show a +1 offset.

The issue comes when in SPFX you dont replicate this behavior, and you end up creating a date in -8 and then saving in with .ToIsoString(), but still showing the dates with .ToLocalDate().

This is a really complicated issue, but I hope you find this useful.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.