2

I have a service(Language: VB.NET, Framework:.NET 3.5) that returns a dataset from which I read a date. The value of the column in the database is: "1980-03-30 00:00:00.000".

In a client(Language: C#) that uses .NET 3.5, the value is coming thorough as : 3/30/1980 12:00:00 AM

However, when I change the same client to use .NET 4 or .NET 4.5, the date which comes through the service is: 3/29/1980 11:00:00 PM

Ashish Shakya
  • 127
  • 1
  • 6

1 Answers1

3

The difference in DateTime values is not because of .Net framework, its because of the locale settings.

Never pass DateTime values through your web service, pass DateTimeOffset and then convert to DateTime type in your client.

Habib
  • 212,447
  • 27
  • 392
  • 421
  • I'm not passing a DateTime object. It's a part of the dataset. – Ashish Shakya Nov 26 '13 at 16:40
  • @AshishShakya, [returning DataSet is bad](http://stackoverflow.com/questions/1659402/to-return-a-dataset-in-a-web-service-or-not) but its probably off topic here, You have to modify your DataSet and return a column of `DateTimeOffset` type, created from the original `DateTime` object, and use that. – Habib Nov 26 '13 at 16:45
  • The web service is setup to just call a stored procedure and returns the result to the client. In the database, the column is a `DateTime`. I do not have the option of changing how the value is stored in the database at this point. I can read the dataset and transform the datetime to datetimeoffset and pass a processed dataset back to the client. However, is there any thing else that will solve the issue? – Ashish Shakya Nov 26 '13 at 17:08
  • @AshishShakya, I don't know of any other way, I had this issue once and I end up returning `DateTimeOffset` column instead of `DateTime`, You can get the `DateTimeOffset` in your proc see [this](http://stackoverflow.com/questions/2008522/sql-server-datetime-to-datetimeoffset) or modify the `DataSet` in your web service before sending. – Habib Nov 26 '13 at 17:45
  • Thank you @Habib. I'll try out your suggestions. – Ashish Shakya Nov 27 '13 at 15:58