Solved

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

Posted on 2006-06-21
2
845 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…

751 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