In past Sitecore project we've discovered unexpected issue in the datetime field behavior. Our client organizes a lot of different events (like trainings and webinars) and some of them are planned for a year ahead.Once it occurred that many registered participants were one hour late for an event and were left disappointed as they were sure they came in time.
Why? OK, let’s add a couple of fields and set some date and time in future:
Looks nice, now let’s move into the future (e.g. 30 May 2017) and see what happens:
Suddenly ‘Date field’ have different date (day before) and time has decreased for an hour! To understand this we need to remember how both date and datetime fields are stored in sitecore:
Initially we selected 1 June in date field, but sitecore stores dates in UTC while displaying them in server time zone. That means it actually stores date different from the selected. And second thing in this situation is daylight saving shift. It is ‘winter time’ in February and Sitecore uses it to make UTC value from selected time and to restore field value from UTC. But after server time zone moves to ‘summer time’ difference between UTC and server time changes. And this floating difference will cause not only stored time change but even date.
What can we do? Main issue here appears when content author creates event in future in different location, where even daylight saving shift is different and what author really needs is just to set ‘3 PM local time’ and be sure it will stay ‘3 PM local time that day’. The simplest solution is to set sitecore setting ‘ServerTimeZone’ to UTC:
<setting name="ServerTimeZone" value="UTC">
That will force Sitecore to show actual stored datetime and avoid floating behavior. Make sure you are using only UTC time in your code and beware that dates and times will be shifted in Sitecore after setting change.