TadSter
asked on
Help with date query
I am querying SQL from Visual Studio 2005 query window.
SELECT code, name, amount, mydatetime
FROM myTable
WHERE (mydatetime = '3/28/2011 05:28:35 PM')
I get an SQL Execution Error
Operator/operand type mismatch
How do change my query to only return that specific date/time.
SELECT code, name, amount, mydatetime
FROM myTable
WHERE (mydatetime = '3/28/2011 05:28:35 PM')
I get an SQL Execution Error
Operator/operand type mismatch
How do change my query to only return that specific date/time.
Try to use
SELECT code, name, amount, mydatetime
FROM myTable
WHERE (mydatetime = '2011-28-3 05:28:35')
SELECT code, name, amount, mydatetime
FROM myTable
WHERE (mydatetime = '2011-28-3 05:28:35')
you can use
WHERE (mydatetime = '2011-03-28 17:28:35')
WHERE (mydatetime = '2011-03-28 17:28:35')
ASKER
None of these work. I keep getting the same error.
It might be worth noting that this is a FoxPro table. Perhaps that will make a difference in the syntax. Please excuse my ignorance on this. The error message source is "Microsoft OLE DB Provider for Visual FoxPro"
Also I checked the properties for the date field to be sure that it is a date field. It is: OleDbType.DBTimeStamp
Hope this helps.
It might be worth noting that this is a FoxPro table. Perhaps that will make a difference in the syntax. Please excuse my ignorance on this. The error message source is "Microsoft OLE DB Provider for Visual FoxPro"
Also I checked the properties for the date field to be sure that it is a date field. It is: OleDbType.DBTimeStamp
Hope this helps.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice!
SELECT code, name, amount, mydatetime
FROM myTable
WHERE (mydatetime = {^2011/03/28 17:28:35})
This works. The parser complained about it, but the query ran perfectly. Apparently the parser doesn't recognize this as a legitimate query, but I just ignored the warning.
FoxPro calls this a "date literal"
SELECT code, name, amount, mydatetime
FROM myTable
WHERE (mydatetime = {^2011/03/28 17:28:35})
This works. The parser complained about it, but the query ran perfectly. Apparently the parser doesn't recognize this as a legitimate query, but I just ignored the warning.
FoxPro calls this a "date literal"
SELECT code, name, amount, mydatetime
FROM myTable
WHERE (mydatetime = '2011-28-3 05:28:35 PM')