HighTechTalks DotNet Forums  

ISO datetimes transmitted as strings to localized Sql Server

Dotnet Internationalization microsoft.public.dotnet.internationalization


Discuss ISO datetimes transmitted as strings to localized Sql Server in the Dotnet Internationalization forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
adi_lazar
 
Posts: n/a

Default ISO datetimes transmitted as strings to localized Sql Server - 10-18-2007 , 04:36 AM






I have an web app in .net 2.0 that is using datetime and this is displayed
and can be input in the current locale( different from country to country:
Germany = MM.dd.yyyy, US, french or australian).
I need to update sql server datetimes with the correct values.
The Sql Server could be localized in another country (ex. web app in Germany
and Sql server in France).

What is the correct approach to cover all the possible datetime formating
differences ?

I read about ISO 8601 dates, but when I tried to use the following Sql
statement:
string cmd = string.Format("UPDATE myTable1 SET datetime1 = '{0}'",
myLocalDate.ToString("yyyy-MM-ddTHH:mm:ss.fffff",
CultureInfo.InvariantCulture));
I'm getting an error on sql server about bad format of char trying to cast
to datetime !!??

What am I doing wrong ?

Thnx for any advice



Reply With Quote
  #2  
Old   
Mihai N.
 
Posts: n/a

Default Re: ISO datetimes transmitted as strings to localized Sql Server - 10-19-2007 , 04:03 AM






Quote:
I read about ISO 8601 dates, but when I tried to use the following Sql
statement:
string cmd = string.Format("UPDATE myTable1 SET datetime1 = '{0}'",
myLocalDate.ToString("yyyy-MM-ddTHH:mm:ss.fffff",
CultureInfo.InvariantCulture));
I'm getting an error on sql server about bad format of char trying to cast
to datetime !!??

What am I doing wrong ?
I don't know what are you doing wrong, but a locale-independent date format
(iso 8601 is perfect) is the right thing to do.
Maybe you also have to configure the sql server to accept dates in that
format?
You might want to check if the SQL server has something like
SET DateStyle TO 'ISO' (PostgreSQL)
MS SQL 2000 (I don't know about newer versions) did not directly
support ISO 8601, but you could use SET DATEFORMAT MDY and it would
accept the string you are building (YYYY-MM-DDTHH:MM:SS.fff)

--
Mihai Nita [Microsoft MVP, Windows - SDK]
http://www.mihai-nita.net
------------------------------------------
Replace _year_ with _ to get the real email


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.