Solved

Dataset from webservice - datetime columns are having offsets applied

Posted on 2009-04-14
2
554 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
[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
2 Comments
 
LVL 14

Accepted Solution

by:
GiftsonDJohn earned 500 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

2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Validation for Passport expiry in asp.net 2 32
FTP recursive download files 5 27
asp.net repeater server posting 5 38
Difference between Highcharts and Mapbox 10 44
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 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