Solved

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

Posted on 2010-08-18
4
496 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
Comment Utility
       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
Comment Utility
You can drastically reduce that by removing "lots" of redundant code, but serves me perfect.
0
 

Author Closing Comment

by:MWilliamsBolton
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now