1

We have an ASP.NET website and an SQL database hosted in US. Whenever I use the function Now() in VB.NET and getdate() in SQL, I get the US' current time. The problem is, the client is in the Philippines which is on GMT+8 Time Zone. My question is, is there any way I can set the Time Zone of a specific database and website so that when I use the functions, I'll get the Philippine's current time? How do you deal with this? As much as possible, we don't want to do subtraction or addition to the result date of the functions since in the future, clients will be from other country. It will give us headache updating the codes if we do that.

Thank you in advance!

kazinix
  • 28,987
  • 33
  • 107
  • 157

1 Answers1

3

Given that your clients may be in different time zones, you should store a timezone for the clients, that they (or you) can set as a preference for their account. Store all dates+times as UTC, and then convert to their timezone when displaying results in your interface.

This question has already been addressed to a great extent in the following question: How to work with time zones in ASP.NET?

Follow-up: Unfortunately, the SQL server date is a system-level setting, so it's not really something that can be manipulated on a per-session basis. It sounds like you will need to make some code changes, but you can isolate them.

  1. Do you have a session-level variable which contains the client time zone offset? If not, create one.

  2. Create a small date/time utility class.

  3. In the utility class, provide 3 methods to: (1) get the current date/time (offset to the client's time zone) (2) pass in a database date/time to return the time offset for the client's TZ. (3) pass in a time from the client to subtract out the client's TZ difference.

You will have to make code changes, but you can probably use those utility functions to wrap inputs and outputs everywhere, centralizing the logic. Microsoft has a page about mis-steps to avoid when using the DateTime class and manipulating time zones: http://msdn.microsoft.com/en-us/library/ms973825.aspx#datetime_topic1a

Community
  • 1
  • 1
John S
  • 79
  • 2
  • thanks for answering. Aside from manipulating the time before displaying, is there any other way? We have another application, existing one, which has the same scenario, I think updating codes will be a pain. – kazinix Oct 27 '11 at 03:27
  • Unfortunately, the SQL server date is a system-level setting, so it's not really something that can be manipulated on a per-session basis. I would plan to use getutcdate() in SQL server. – John S Oct 27 '11 at 04:36