Solved

Setting Time Zone for Windows Form App

Posted on 2008-06-11
6
450 Views
Last Modified: 2013-11-26
I have a .NET visual Studio 2005 question...  I have a client app that runs off desktops across the world.  It allows the user's to run in their local culture.  All of the database access is handled on a central server (located in the US on the east coast in the EST time zone).  We use remoting to enable the client and the "business" (database) code to communicate and subsequently issue stored proc calls.  We wanted to have all date/times that were saved into the database be in the EST timezone (most users are in the US and it seemed confusing to store dates/times in local time zones and really not have a reference as to what time zone it was in and therefore, not knowing REALLY what time an action was initiated).

Anyway, currently, when the users outside of the EST time zone use the system, their local date/time is entered into the database.

Is there an EASY way to change the timezone used by a thread (similar to the way we can change the culture of the thread) so that all interaction for the client thread could be done in the same timezone as the dates/times we want to store in the database?  I don't really want to change the visual format of the dates/times, just the zone.

0
Comment
Question by:ablesa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 7

Expert Comment

by:sj_hicks
ID: 21766300
I reckon the best way would be to write times in your DB in UTC.  Easy to convert from local to UTC (myLocalTime.ToUniversaTime) and back the other way (myUTCTime.ToLocalTime).
0
 
LVL 11

Expert Comment

by:AkisC
ID: 21767378
What I would do is to have an extra filed in my database (e.g. EST_Timezone) and set its default value to Now()
So any time a user adds a new record the field will have the server time
0
 

Author Comment

by:ablesa
ID: 21770370
thanks to you both for your comments.  Those solutions might have been the way to go 9 months ago, but now, we are testing and getting ready to deploy to users by Aug 1.  It seems that I will have to convert the dates to EST before running the stored procs....  If you have any other "quick fix" ideas, please let me know.

Thanks!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:AkisC
ID: 21775379
I still suggest... Have an extra filed in your database (e.g. EST_Timezone) and set its default value to Now(), then have the stored procs to return this value to you. It is safest than converting it programmatically
0
 

Accepted Solution

by:
ablesa earned 0 total points
ID: 21802539
As I dug into this issue more, I found that the real problem was in the serialization of the data coming back from the server.  It was taking any date values passed to the client and converting them to their local timezone instead of just passing the date back as it was when it was fetched from the database.  After some digging, I learned why it was converting the dates on the serialization...

I am on Framework 2.0 and within ADO.Net 2.0, there's a property on the dataTable Columns called DataSetDateTime and it can have 4 different values:
Local
 DateTime is always stored in Local. If Utc or Unspecified is assigned to a column in this mode, it is first converted into Local. Serialization in this mode is always performed in Local. There is an offset during serialization.
 
Unspecified
 DateTime is always stored in Unspecified. If Local or Utc is assigned to a column in this mode, it is first converted into Unspecified. Serialization in this mode does not cause an offset.
 
UnspecifiedLocal
 DateTime is stored in Unspecified. If Local or Utc is assigned to a column in this mode, it is first converted into Unspecified. Serialization in this mode causes offset. This is the default behavior and is backward compatible. This option should be thought of as being Unspecified in storage but applying an offset that is similar to Local during serialization.
 
Utc
 DateTime is stored in Universal Coordinated Time (UTC). If Local or Unspecified is assigned to a column in this mode, it is first converted into Utc format. Serialization in this mode is always performed in Utc. There is no offset during serialization.
 

I examined my datatable date columns right after it was pulled from SQL Server and it had DataSetDateTime set to UnspecifiedLocal (which is the default).  I put some code in to loop thru the datatable columns and for those that are date types, I set their DataSetDateTime to Unspecified and it worked...  It stopped converting my dates to the user's local time zone.

Thanks to you both for trying to help solve this.  Just thought I'd put my solution here in case it was useful to someone else.
0
 
LVL 11

Expert Comment

by:AkisC
ID: 21802901
Thank you for taking the time to make us "smarter" with your time investment.

Have fun coding...;)
0

Featured Post

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question