4

I am creating a web chat application using ASP.NET. I have got the chat system to work as messages are sent and relayed back to the clients. But there was something I noticed but never thought it would be a problem. I am from England and the chat application is sitting on servers in America and noticed when the message displayed the time, the times were situated in American time zones. How would I go about setting the timezones that will correspond to the user's timezone.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
user1240045
  • 109
  • 1
  • 1
  • 9

2 Answers2

5

Store your data in UTC. Always. So instead of storing GETDATE(), store GETUTCDATE() (or SYSUTCDATETIME() in SQL Server 2008+).

This makes it very easy to convert all times in a chat to whatever time zone the user is in. And there are plenty of facilities in ASP.NET to help you with this conversion if you don't want to do it in SQL.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
0

I am changing the date zone to the Brazilian time that was my need.

VALUES (GETDATE () AT TIME ZONE 'UTC' AT TIME ZONE 'E. South America Standard Time');
think-maths
  • 917
  • 2
  • 10
  • 28