Korazy

I have a problem with converting a string to date because of culture settings.

On a Windows 2000 Server, the .NET framework 2.0 was installed with the windows regional settings set to English Canadian (dd/mm/yyyy). The windows regional settings have been changed to English US (mm/dd/yyyy). My .net service still shows the culture short date format as 'dd/mm/yyyy' and therefore when trying to convert a date value of '05/30/2007' to a DateTime type, I get the exception 'String was not recognized as a valid DateTime.'. What do I need to change to correct this The windows regional settings are all set for date formats 'mm/dd/yyyy'.



Re: .NET Base Class Library Framework Culture Info not changing after chaning windows regional settings

Korazy

To get around this I changed my string to datetime conversion to the following. This works for me because I know my string date sources are always 'mm/dd/yyyy'. If there is a better approach, please reply.

Public Shared Function ConvertDateTime(ByVal Value As String) As DateTime
Dim ci As System.Globalization.CultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture
Dim dti As System.Globalization.DateTimeFormatInfo = ci.DateTimeFormat.Clone
dti.ShortDatePattern = "MM/dd/yyyy"
Return Convert.ToDateTime(Value, dti)
End Function





Re: .NET Base Class Library Framework Culture Info not changing after chaning windows regional settings

timvw

You could also use DateTime.ParseExact...