I'm receiving reports from my users that my application is handling dates incorrectly. I've confirmed that this is indeed happening for users outside of my network, but doesn't seem to be occurring with users on my local network.
My application is a .NET 2.0 distributed app using .NET 2.0 web services for data access. It seems that any time I return a date from the web service, the application is for some reason subtracting 1 day from that date.
For example, if I return information on a Customer, the web service response will give me a date such as:
However, the program is displaying this as 2/5/2007. I'm not doing any sort of manipulation with the date. The web service returns a dataset, and I simply iterate the datatable's row collection and convert that column to a datetime using the following:
However, the program is displaying this as 2/5/2007. I'm not doing any sort of manipulation with the date.
You aren't doing any manipulation, but the framework may do. Have you checked the full DateTime object and not only the date part of it?
In this line you cast an object to a DateTime. Assuming that your onject is a string, DateTime.Parse will be invoked to do the conversion. If you do not pass any additional parameters, the local CultureInfo and time zone setting will influence the result.
E.g. for me (in Germany) the result of System.DateTime.Parse( "2007-02-06T00:00:00-05:00" ) is 2007-02-06T06:00.
I recommend that you directly call DateTime.Parse and pass the appropriate CultureInfo to the method. Eventually you should use the CultureInfo in your output methods, too.
Thanks for the suggestions, Tim. I discovered the "problem" not long after posting my first message. I was unaware that the web service was adding a time zone offset. I've since reconfigured the web service to return DataSets without the time zone offset.