isDate in VBScript  of DTS vs. isDate in MS SQL Query

Posted on 2006-06-21
Last Modified: 2008-01-16

  I am trying to import some dates from a text to a table on MS SQL 2000 using the  ActiveXScript. I am noticing something funny when I use the isDate in VBSCript. It is validating some dates listed below which arent dates (as MS SQL Query will point out). When I use th CDATE next ,as expected, I will get a character cast conversion error.
List of dates isDate in VbSCript of ActiveXScript is validating:
There will be so many other examples as I cant control the data set received. Is there a way to correct this issue i.e have isDate work like it does on MS SQL Query Analyser so that CDATE doesnt complain of character cast conversions?

Question by:LuckyLucks

Expert Comment

ID: 16952582
Does it work if you concantenate pound signs?

LVL 75

Accepted Solution

Anthony Perkins earned 500 total points
ID: 16956880
>>It is validating some dates listed below which arent dates <<
Actually they are valid dates at least as far as VBScript is concerned.  See here fromt the VBScript help for IsDate:

>>IsDate returns True if the expression is a date or is recognizable as a valid date; otherwise, it returns False. In Microsoft Windows, the range of valid dates is January 1, 100 A.D. through December 31, 9999 A.D.; the ranges vary among operating systems.<<

Your error is to assume that VBScript IsDate function is the same as the T-SQL ISDATE() that is plainly not the case.

The solution is to use a function something like this (Untested):

Function IsValidTSQLDateTime (ByVal sDat)
Const FROM_DATE = #1/1/1753#, _
    TO_DATE = #12/31/9999#

Dim Dat

If IsDate(sDat) Then
   Dat = CDate(sDat)
   If Dat >=  FROM_DATE and Dat <= TO_DATE Then
       IsValidTSQLDateTime = Dat
       IsValidTSQLDateTime = Null
    IsValidTSQLDateTime = Null
End If

End Function

I will leave it as an exercise for the similar IsValidTSQLSmallDateTime() function.

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

856 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