Link to home
Start Free TrialLog in
Avatar of TadSter
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.
Avatar of Imran Javed Zia
Imran Javed Zia
Flag of Pakistan image

Try to use
SELECT     code, name, amount, mydatetime
FROM         myTable
WHERE     (mydatetime = '2011-28-3 05:28:35 PM')
Try to use
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')
Avatar of TadSter
TadSter

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.
ASKER CERTIFIED SOLUTION
Avatar of Sara bhai
Sara bhai
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TadSter

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"