ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Dates in a SQL Statement (https://www.excelbanter.com/excel-programming/411781-dates-sql-statement.html)

NateBuckley

Dates in a SQL Statement
 
Hello,

I'm using ADODB to connect to an ACCESS database I've set up. I have a few
fields that are Date types and I send the SQL statement via a string, the
thing is I'm getting errors when trying to use Variables that are dates in
the string.

My SQL Statement

strSQL = "SELECT * FROM tblMain WHERE [fldDateFrom] = '" & dateFrom & "'"

it'll turn my variable dateFrom into just a string. So doesn't match up when
it comes to putting this value into the database.

Anyway to make sure this gets put in as a Date type?

Sorry If that's unclear.

Nate

Andrew Taylor

Dates in a SQL Statement
 
I would use the following:
strSQL = "SELECT * FROM tblMain WHERE [fldDateFrom] = '" &
Format(dateFrom,"yyyy-mm-dd") & "'"



On 30 May, 15:40, NateBuckley
wrote:
Hello,

I'm using ADODB to connect to an ACCESS database I've set up. I have a few
fields that are Date types and I send the SQL statement via a string, the
thing is I'm getting errors when trying to use Variables that are dates in
the string.

My SQL Statement

strSQL = "SELECT * FROM tblMain WHERE [fldDateFrom] = '" & dateFrom & "'"

it'll turn my variable dateFrom into just a string. So doesn't match up when
it comes to putting this value into the database.

Anyway to make sure this gets put in as a Date type?

Sorry If that's unclear.

Nate




All times are GMT +1. The time now is 01:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com