Building SQL Commands in .NET with DateTime that run against SQL Servers with different regional set

  • Thread starter Thread starter Andrew Smith
  • Start date Start date
A

Andrew Smith

Hi,

I'm bulding SQL Commands with
System.Threading.Thread.CurrentThread.CurrentCulture = cu

String.Format(MSSQLComand, Startdate.ToShortDateString,
EndDate.ToShortDateString)

When I'm running this against an English Database Server this works, how
ever this does not againt an Italian one.

What is best practice to fight this localization issue?

Thanks in advance for any advice
Andrew
 
Hi Bob,

thanks for your answer. I found out that I can read this format from SQL
Server and read in .NET with:

select convert(datetime,'20040508',112)

Dim dt as DateTime = DateTime.ParseExact("20040508", "yyyyMMdd", Nothing)

http://www.dotnet247.com/247reference/msgs/44/220791.aspx

Do you know the easiest way how to bring a datetime value to the YYYYMMDD
String Format?

Thanks in advance for any advice

Andrew
 
Andrew,

One way is to use the Format function. For example:

Dim dt As DateTime = Now
Dim dtString As String

dtString = Format(dt, "yyyyMMdd")
MsgBox(dtString)

Kerry Moorman
 
Back
Top