globalization problem

F

francois

hi,

I have an ASP.NET application with a piece of code that looks like this:

(it is a VB.NET snippet)

Thread.CurrentThread.CurrentCulture = New
CultureInfo(Session.Item("Culture").ToString)
Thread.CurrentThread.CurrentUICulture = New
CultureInfo(Session.Item("Culture").ToString)
Dim cultureSpecificDate As Date = Request.QueryString("date").Trim()


the QueryString object is a key-value collection type, (similar to a
hashtable). It is a NameValueCollection to be exact, but I believe that this
is not an important point.

Let say the string returned by Request.QueryString("date").Trim() is
"20/7/2004 0:00:00"

If the culture loaded at that time is: english then the Date object created
will contain a correct value which is 20/7/2004. But if the culture loaded
is a bit exotic, like the thai culture (which i believe follows a budhist
calendar type), the date object created will be 7/20/1461
That is a problem as later on that date will be used for some SQL commands
and look for that related to the date 20th of july 1461 which obviously does
not exist as the year is tottally different (543 years of difference).

Then I have 2 questions:
1. how can i solve this and always have the right date? (2004 for my SQL
stored procedure). Also I would like a generic solution that will work for
any culture. I would like to avoid any hardcoded date transformation.
2. 2004 in the thai calender correspond 2547 (2004 + 543 = 2547)
Then it seems that when the date object instance is created there is a
problem as it transform 2004 into 1461 (2004 -543 = 1461), which basically
is wrong.

Best regards and tx in advance,

Francois
 
S

Shan Plourde

Dates are repersented in many different ways depending on the culture
selected. I believe that Thread.CurrentCulture is responsible for how a
string containing a date would be parsed.

If your URL parameter is always in the format "day/month/year hh:mm:ss"
yet your Thread.CurrentCulture varies depending on the user's current
culture set, then you should probably parse the string manually, or
better yet try looking at System.Globalization.DateTimeFormatInfo. This
way you can leverage .NET to do the parsing of your URL parameter date.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,811
Latest member
SaulFernan

Latest Threads

Top