Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Dataset from webservice - datetime columns are having offsets applied

Posted on 2009-04-14
2
Medium Priority
?
586 Views
Last Modified: 2012-05-06
We have a client app which gets its data from a server. We use web services to run sql statements and a dataset is returned which contains the information.

The client app is used in different countries and the problem we have is that when the dataset is returned, all date columns are having timezone offset's applied. How can we stop this without having to modify the client application? Is there a setting inside the web service or server i can use instead? Changing regional/date settings on the client machine is completely out of the question.

At the moment, whenever we request a date column, we have to select it in sql like this; "Select convert(varchar, datecol) datecol from sometable"

Its not ideal...
0
Comment
Question by:tfsln
2 Comments
 
LVL 14

Accepted Solution

by:
GiftsonDJohn earned 2000 total points
ID: 24144555
Hi,

This is a default behavior of .Net Frameworks.

See the following for some background on this:
http://blogs.msdn.com/brada/archive/2004/04/13/112784.aspx
http://msdn.microsoft.com/netframework/default.aspx?pull=/library/en-us/dndotnet/html/datetimecode.asp#datetime_topic4

The Xml serializer always assumes that DateTime values being serialized represent local machine time, so it applies the local time zone offset as the offset portion of the encoded XML time. When this is deserialized on the client, the original offset is subtracted from the value being parsed, and the current machine's time-zone offset is added. In order to get the "raw datetime" on your client, you will have to work around this.

See the following post for more on this:
http://blogs.msdn.com/bclteam/archive/2005/03/07/387677.aspx

Your options are:
1. Change the column type to be Int64 or String
2. Call DateTime.ToLocalTime on the DateTime before putting it in the DataSet and call DateTime.ToUniversalTime after taking it out. This effectively "cancels out" the adjustment and can be used whether you are dealing with a whole date or a UTC time.
3. Make all machines use the same time zone.
4. If you have a chance to pre-process the XML before it is sent out, you can manually strip out the time zone offset out of the XML text. For example, a typical XML date and time looks like this: 2005-01-28T03:14:42.0000000-07:00. You can use a Regex to remove the -07:00. You do not need to re-inject anything on the other end, as no adjustment is made if there is no time zone information. Do not try to replace the time zone offset with Z or +00:00. While technically a more correct representation, the existence of time zone information will cause the serializer to do an extra conversion to local.

Reference taken from
http://social.msdn.microsoft.com/Forums/en-US/netfxcompact/thread/7dfcf15a-825f-46db-a61a-8696833e7dcf

0
 

Author Closing Comment

by:tfsln
ID: 31570218
Great answer, thank you
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

885 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