-1

I'm trying to pass a DateTime object to my webservice. The system keeps telling me that there's an SqlDateOverflow error. I've tried converting the object to a string but the same error persists.

How can I pass a DateTime object from a system that uses a certain culture, and the server on which the webservice resides uses a different culture? Is there any way to standardize the object so that any system, regardless of its culture, can parse the object to its DateTime equivalent?

I have tried using the DateTime.Parse method, the DateTime.TryParse method, and even the DateTime.ParseExact method but all of them result in 'SqlDateOverflow'.

curtisk
  • 19,950
  • 4
  • 55
  • 71
Juan
  • 45
  • 2
  • 4
  • 1
    What is the date you are trying to pass through? Does it **fit** into a SQL `DATETIME` (January 1, 1753, through December 31, 9999)? – Oded Nov 16 '12 at 12:53
  • If you want to be culture independent use `CultureInfo.InvariantCulture`. – Tim Schmelter Nov 16 '12 at 12:53

3 Answers3

0

I would always pass dates as strings in ISO8601 format

See Convert dateTime to ISO format yyyy-mm-dd hh:mm:ss in C#

Community
  • 1
  • 1
Vicki
  • 668
  • 7
  • 21
0

To avoid this problem you could modify the SQL script / procedure you call in your webservice, addin at the start this:

SET DATEFORMAT dmy; -- day/month/year

or

SET DATEFORMAT mdy; -- month/day/year

This way, if you pass it as a string correctly formatted, your SQL engine will always treat it correctly.

LittleSweetSeas
  • 6,786
  • 2
  • 21
  • 26
0

Without more details as far as what culture you are going to/from, this may help your issue at hand

DateTime.Parse(yourDateTimeString,CultureInfo.InvariantCulture)
curtisk
  • 19,950
  • 4
  • 55
  • 71