locked
Calendar Control- culture setting RRS feed

  • Question

  • User1389224148 posted

    Hi ,

    The issue I have is when the langauge is 'en-US' the isDate function validates the string as true,but when I change the language to Spanish,even though the string is correct the isdate function fails. Is there some setting that I am missing when changing the languages or is this a format issue?If so how do I go about resolving it?

     Public Function FormatAS400Date(ByVal TestDate As String) As Date
            Dim sDate As String = ""
    
            If TestDate.Length = 7 Then
    
                sDate = TestDate.Substring(3, 2) & "/" & TestDate.Substring(5, 2) & "/" & TestDate.Substring(1, 2)
    
            End If
    
            If IsDate(sDate.Trim) = True Then
    
                Return Convert.ToDateTime(sDate)
    
            Else
                Return Date.MinValue
            End If
        End Function

     

    Friday, October 21, 2011 9:26 AM

Answers

  • User1389224148 posted

    I was able to resolve this.For anyone who is stuck on this:

     Public Function FormatTestDate(ByVal TestDate As String) As Date
            Dim sDate As String = ""
            Dim thedate As Date
    
            If TestDate.Length = 7 Then
                sDate = TestDate.Substring(3, 2) & "/" & TestDate.Substring(5, 2) & "/" & TestDate .Substring(1, 2)
    
                thedate = Date.ParseExact(sDate, "MM/dd/yy", CultureInfo.InvariantCulture)
            End If
    
            'If IsDate(sDate.Trim) = True Then
            If IsDate(thedate) = True Then
                'Return Convert.ToDateTime(sDate)
                Return Convert.ToDateTime(thedate)
            Else
                Return Date.MinValue
            End If
        End Function
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 21, 2011 9:44 AM

All replies

  • User-1028151323 posted

    The date format will be different. US is mm/dd/yyyy and most european countries use dd/mm/yyyy. 

    Friday, October 21, 2011 9:34 AM
  • User1389224148 posted

    So are you saying if I change the order of the string it would work.Is there an international format?

    Friday, October 21, 2011 9:36 AM
  • User-1028151323 posted

    There may be some way of formatting it better but I have split the string on "/" and reordered it. Don't know if that option works for you.

    Friday, October 21, 2011 9:42 AM
  • User1389224148 posted

    I was able to resolve this.For anyone who is stuck on this:

     Public Function FormatTestDate(ByVal TestDate As String) As Date
            Dim sDate As String = ""
            Dim thedate As Date
    
            If TestDate.Length = 7 Then
                sDate = TestDate.Substring(3, 2) & "/" & TestDate.Substring(5, 2) & "/" & TestDate .Substring(1, 2)
    
                thedate = Date.ParseExact(sDate, "MM/dd/yy", CultureInfo.InvariantCulture)
            End If
    
            'If IsDate(sDate.Trim) = True Then
            If IsDate(thedate) = True Then
                'Return Convert.ToDateTime(sDate)
                Return Convert.ToDateTime(thedate)
            Else
                Return Date.MinValue
            End If
        End Function
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 21, 2011 9:44 AM