Helpful Information
 
 
Category: Visual Basic Programming
IsDate - not so obvious

I realise that the IsDate function returns true if the argument passed to it can be converted to a date....but i'm not exactly sure what formats VBScript will recognise as dates....

the examples i've seen don't cover the format i want to use, so can somebody just provide a quick answer of what IsDate will return if i pass it a date in the format: 24/Jan/1984, that is, dd/mmm/yyyy....hopefully it will return true

Well, first I would say try it and see.
Here is more info on the function:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vsfctisdate.asp

Be aware that the windows locale will affect dates, currency etc.

In particular dates dd/mm/yyyy and mm/dd/yyyy are ambiguous for small values of dd and mm for a lot of windows date functions.

If you have a locale which takes dd/mm/yyyy but put an invalid month value in and have a day that will be a valid month, the values will be magically switched.
eg. 10/20/2003 will be converted into 20th October 2003 which under the dd/mm/yyyy will actually be 20/10/2003.

So the try it and see method may get a bit confusing.

you could always detect your 80% locales and provide a parse function depending on the locale, assuring that the date is properly formatted before entering your code.

But from personal experience, I have found that usually problems like these are best kept out of back end code, and solved by very very rigid user input code and clear instructions. If this is NOT a user interface input method for your date value, then I would analyze your data and rule out certain "out there" circumstances, and only code for the crazy stuff when and if it occurs. This may sound lazy, but as I am paid hourly as a freelance consultant, I just inform the client of my decision and they are usually thankful to save the money up front.










privacy (GDPR)