Cast and Convert functions are not supported on converting the column to date time format (in vbscript - Excel adodb)

687 views Asked by At

I have written a vbscript to connect the excel file (.xlsx) as a database using ADODB connection. I want to extract the records from excel file which has the values in 'StartDate' column greater than '15/05/2015', but on executing a adodb query an error is thrown as "Data type mismatch in criteria expression."

I tried to convert the 'StartDate' column as date format using 'Convert' and 'Cast' functions, but it is not supported. How to write a query to retrieve the records?

The values in 'StartDate' column in excel looks like "21/05/2015 0:00" and on double clicking the field it looks like "21/05/2015 12:00:00 AM"

The queries I had tried (Data Mismatch error is thrown for all the queries):

Select * from [Student$] where StartDate >= '15/05/2015' 
Select * from [Student$] where StartDate >= '15/05/2015  12:00:00 AM'
Select * from [Student$] where StartDate >= '15/05/2015  00:00:00.000'
Select * from [Student$] where StartDate >= '15/05/2015  0:00'
1

There are 1 answers

0
Ekkehard.Horner On BEST ANSWER

The marker for date literals is #, so use

Select * from [Student$] where StartDate >= #15/5/2015#

cf. here