views:

516

answers:

2

Hi folks,

i'm not sure how to correctly format a .NET DateTimeOffset variable, as a string, for SqlServer 2008 to correct parse the value.

currently, if i provide the default .ToString() value from a normal DateTimeOffset value, it errors.

Here is a sample .ToString() value that errors (eg. Sql2008 doesn't like it): '25/12/2008 2:12:21 PM +00:00'

any suggestions? cheers :)

Update

Just to clarify, I know the .ToString() is not in a compatible Sql2008 format. I'm hoping someone might be able to tell me what i need to provide to an IFormattableProvider argument (for the .ToString() method) which is legit for the new DateTimeOffset SqlDataType.

Answer

I've answered it myself. I figured out the correct IFormattableProvider args

myDateTimeOffest.ToString("yyyy-MM-dd HH:mm:ss.ffffff zzz")

cheers!

A: 

DateToOffset.ToString supports passing in a format string to control the output. Try passing in a format string which is compatible with SQL 2008

JaredPar
Yes JaredPar - that's EXACTLY what i'm asking in this question -> i'm not sure what that would be. I'll update the OP.
Pure.Krome
+1  A: 

According to BOL the types are compatible.

What error are you receiving? Are you specifying the Type System Version to be 2008 in your connection string?

YonahW
>>Type System Version to be 2008 in your connection string. Er.. nope. what is that? this is my conn string: Data Source=fukchop;Initial Catalog=Osm;Integrated Security=SSPI;
Pure.Krome