Solved

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

Posted on 2010-08-18
4
505 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
  • 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

786 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