Solved

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

Posted on 2006-06-21
2
821 Views
Last Modified: 2008-01-16
Hi:

  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:
01/01/0101
12/12/1212
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?

Thanks
0
Comment
Question by:LuckyLucks
2 Comments
 
LVL 3

Expert Comment

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

IsDate(#01/01/0101#)
0
 
LVL 75

Accepted Solution

by:
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
   Else
       IsValidTSQLDateTime = Null
Else
    IsValidTSQLDateTime = Null
End If

End Function

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

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now