Solved

Convert Date in ASP.Net (VB) depending on browser language

Posted on 2010-08-18
4
508 Views
Last Modified: 2012-06-27
I have a text box that takes in a date string. I need to check that the date is in the right format and convert it to a date type.

The users are in US and UK (and possibly other countries) and I want the server procedure to take that into account.

Does anyone have a fully international VB function that does this? (I am thinking that the server has knowledge of the lanuguage of the browser ..?)
0
Comment
Question by:MWilliamsBolton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 33470508
       Public Function GIsDate(ByVal anyString As String) As String
            Dim c4 As Globalization.CultureInfo = Globalization.CultureInfo.CurrentCulture
            Dim kd = c4.IetfLanguageTag.ToString()
            Dim gb As New CultureInfo("en-GB")
            Dim us As New CultureInfo("en-US")
            'anyString = anyString.Replace(".", "/")
            If anyString.Length > 0 Then
                Dim dummyDate As DateTime = DateTime.MinValue
                Dim kp As Double = 0.0
                Try
                    Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US", False)
                    Dim xs As DateTime = DateTime.Parse(anyString, us)
                    kp = xs.ToOADate()
                    Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo(kd, False)
                    Return "T," & kp.ToString
                Catch ed As Exception
                    Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo(kd, False)
                    Try
                        Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo("en-GB", False)
                        Dim xs As DateTime = DateTime.Parse(anyString, gb)
                        kp = xs.ToOADate()
                        Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo(kd, False)
                        Return "T," & kp.ToString
                    Catch ey As Exception
                        Threading.Thread.CurrentThread.CurrentCulture = New CultureInfo(kd, False)
                        Return "F,NotQuite"
                    End Try
                End Try
                'Return True
            Else
                Return "F,NotQuite"
            End If
        End Function
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 33470519
You can drastically reduce that by removing "lots" of redundant code, but serves me perfect.
0
 

Author Closing Comment

by:MWilliamsBolton
ID: 33471253
Although I have not implemented it yet, I can see it is exactly what I needed. Thank you.
0
 
LVL 17

Expert Comment

by:nepaluz
ID: 33471400
The pleasure is all mine. Let us know when you have implemented it whether it serves your purpose (or needs a tweek!)
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question