Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

598 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