Re: Problem with date formatting in SQL command
- From: lyle <lyle.fairfield@xxxxxxxxx>
- Date: Tue, 16 Oct 2007 03:41:16 -0700
On Oct 16, 5:31 am, nartla <bruno.bar...@xxxxxxxxxx> wrote:
On 16 oct, 01:24, Chuck Grimsby <c.grim...@xxxxxxxxxxxxxxxxxxxxxxxx>
wrote:
Format the dateTest variable to YYYY-MM-DD format before enclosing it
in the single quotes:
strSQL = "SELECT ID_PRX, PRX_LIB FROM PRX_TABLE " & _
"WHERE ID_PROJECT = 1000 AND ID_CYCLE <>2 AND " & _
"PRX_END_DATE >= '" & Format(dateTest, "YYYY-MM-DD") & "'*
If there's also a time value in dateTest, use "YYYY-MM-DD HH:NN:SS".
Hello,
Thank you for your answer.
If I just modify the command the way you suggested it and run the app,
I got a message about 'overflow', obviously because dateTest =
"20071016"
So I tried to make the following changes :
dateTest = CStr(Year(Now)) & "-" & CStr(Month(Now)) & "-" &
CStr(Day(Now)) ' dateTest now is "2007-10-16"
strSQL = "SELECT ID_PRX, PRX_LIB FROM PRX_TABLE " & _
"WHERE ID_PROJECT = 1000 AND ID_CYCLE <>2 AND " & _
"PRX_END_DATE >= '" & Format(dateTest, "YYYY-MM-DD") & "'
but i'm still having the same old 3464 error message.
It seems that Access still does not understand that the value after
"PRX_END_DATE >= '" is supposed to be a date, but I don't find a way
to make it work ...
I even tried with "PRX_END_DATE >= CAST(" & dateTest & " AS
DATETIME)" which is supposed to be the right syntax for SQL Server,
but still not working ...
Surely
"PRX_END_DATE >= CAST(" & dateTest & " AS
DATETIME)"would generate a syntax error, or ask SQL to Cast the integer 20071016
as a date, and something like
CAST ('2007-10-16' AS DateTime)
or
CAST ('" & dateTest & "' AS DateTime)
single quote, double quote & dateTest & double quote, single quote
would be needed?
I use CAST ('2007-10-16' AS DateTime) extensively with no problems.
Then again I don't use ODBC, so this may not be applicable.
.
- Follow-Ups:
- Re: Problem with date formatting in SQL command
- From: nartla
- Re: Problem with date formatting in SQL command
- References:
- Problem with date formatting in SQL command
- From: nartla
- Re: Problem with date formatting in SQL command
- From: Chuck Grimsby
- Re: Problem with date formatting in SQL command
- From: nartla
- Problem with date formatting in SQL command
- Prev by Date: Re: Access 2007 Report Formatting...
- Next by Date: Re: Problem with date formatting in SQL command
- Previous by thread: Re: Problem with date formatting in SQL command
- Next by thread: Re: Problem with date formatting in SQL command
- Index(es):
Relevant Pages
|