> This is probably at the operating system level. But fixing this is not
going to solve the problem. When someone logs into the box, the regional
settings might change. And someone else might change them back on you.
Hell, a central server might be going out and adjusting the settings on all
the boxes so they match, once a night.
04 JUL 2015 returned from 15/07/04
Well, no kidding! What kind of input is that? I could come up with six
different dates for that "date" you sent in. The operating system is going
to be more restrictive, of course, but it's not a mindreader, and it's
probably going to guess wrong. At least if you used a 4-digit year (do we
all remember the Y2K problem???), I'd only have two possibilities.
Well it certainly is guessing wrong. I really hate dealing with dates
in ASP, it seems to fight me on them. I've given up for now and come
up with the function copied at the bottom of this post. Its probably
a very inappropriate and cumbersome way of solving the problem, but I
did not have a good day yesterday and I just want a solution now.
This seems to work.
Once again, provide unambiguous input, and you will get unambiguous output!
If you are allowing users to enter dates in a freetext form field, STOP
DOING THAT! NOW! Use a calendar control, or separate dropdowns -- and
VALIDATE before submission!
Alass, I did actually setup the form with nice drop-down boxes for
each date element. These were automatically generated from code and
it looked good and worked well.. However the users didn't like it,
for speed they prefer to type in the date so I was asked to provide a
simple inputbox instead. I pointed out that this could be ambiguous,
but was overruled.
Heres the function I came up with in desparation:
Function ConvertToOracleDate(dtmDate)
Dim i
Dim firstSeparator
Dim secondSeparator
For i = 1 To CInt(Len(dtmDate))
If Not IsNumeric(mid(dtmDate,i,1)) Then
firstSeparator = i
Exit For
End If
Next
For i = firstSeparator + 1 To CInt(Len(dtmDate))
If Not IsNumeric(mid(dtmDate,i,1)) Then
secondSeparator = i
Exit For
End If
Next
'build date
Dim arData(2)
arData(0) = Right("0" & Mid(dtmDate,1,firstSeparator-1),2)
arData(1) = UCase(MonthName(Right("0" &
Mid(dtmDate,firstSeparator+1,secondSeparator-firstSeparator-1),2),True))
arData(2) = Right(dtmDate,Len(dtmDate)-secondSeparator)
ConvertToOracleDate = Join(arData," ")
Erase arData
Set i = Nothing
Dim firstSeparator = Nothing
Dim secondSeparator = Nothing
End Function