?
Solved

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

Posted on 2010-08-18
4
Medium Priority
?
510 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

762 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