user2886050
user2886050

Reputation: 11

ASP classic IsDate return wrong results

I have probably problem with my IIS configuration. Windows Server 2012 Foundation IIS 8 Local system Czech, date format dd.mm.rr ASP classic

IsDAte("18-10-13") - TRUE
IsDAte("18#10#13") - TRUE
IsDAte("18.10.13") - FALSE
IsDAte("18.10.2013") - TRUE

I need to IsDAte(18.10.13) return true. Why now IsDAte(18.10.13) return false?

Upvotes: 0

Views: 2601

Answers (2)

gpinkas
gpinkas

Reputation: 2591

UPDATE:

The isDate check seems to return indifferent results with 2-digit year inputs, so you could use this function to check for valid dates:

function checkDate(datestr)
    dim temp, dt, d, m, y
    
    checkDate = false
    temp = split(datestr, ".")
    if UBound(temp) = 2 then
        d = CInt(temp(0))
        m = CInt(temp(1))
        y = CInt(temp(2))
        if y<100 then
            y = 2000 + y
        end if

        dt = DateSerial(y, m, d)
        if day(dt)=d and month(dt)=m then
            checkDate = true
        end if
    end if
end function

The DateSerial function call and the checks for day and month are inserted to make sure that invalid dates, such as 30.02.2013 will return false. It also supports 4-digit year inputs, but you should be aware that you will run into a Y3k issue with this function in a few hundred years. :)


As @Elie already said, isDate uses the current locale setting. But you can set the locale you want to match the required date format.

dim locale
' uses your current locale and will return false
Response.Write "<p>TEST: " & isDate("15.10.2013") & " --> " & GetLocale() & "</p>"

locale = GetLocale() ' save current locale
SetLocale(1031) ' de_AT

' uses de_AT locale and will return true
Response.Write "<p>TEST: " & isDate("15.10.2013") & " --> " & GetLocale() & "</p>"

SetLocale(locale) ' restore your locale

Find a list of locale ids to find the correct number

Upvotes: 2

Elie
Elie

Reputation: 1140

The IsDate function uses local setting to determine if a string can be converted to a date. More info here.

I don't think that the date settings on Windows Server 2012 offer the "DD.MM.YY" option.

Upvotes: 0

Related Questions