Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2006-06-21
2
Medium Priority
?
859 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 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

782 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