Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

comparing a datetime in WHERE clause inMFC CRecordset

Posted on 2000-03-30
6
Medium Priority
?
422 Views
Last Modified: 2010-08-05
I'm using MFC CRecordset class to select records from an ODBC Data Source (Access).  I'm trying to set a filter for a datetime column (named "Date") compared to a value I'm building from data in my program.

for values of m_strFilter, I've tried tried:
"Date > '03/30/00 10:00:00'"
"Date > '10:00:00 03/30/00'"

... and just about every variation on the date format.  No records are selected (triple checked that they should have been).  I also tried leaving out the time, and comparing against the date only.

I saw some articles referencing the CONVERT function, so I tried that ("Date > CONVERT(datetime,'03/30/00')") However, that gives a CDatabaseException with reason: "CONVERT is an unknown function"
0
Comment
Question by:sniles
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 2672051
Try this:
"[Date] > #2000/03/30 10:00:00#"
or
"[Date] > #2000/03/30#"
0
 

Author Comment

by:sniles
ID: 2673392
I tried those, but they did not work.  With no single quotes around the date field (as in your suggestion), nothing was selected.  When no single quotes were used a record from 3/28/00 and the record from 3/30/00 was selected.
0
 
LVL 10

Expert Comment

by:paasky
ID: 2673587
Hello sniles,

Use CDate() with Access database:

Date > CDate('03/30/00 10:00:00')
Date > CDate('10:00:00 03/30/00')

It converts value to valid date.

Hope this helps,
Paasky
0
10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

 

Author Comment

by:sniles
ID: 2676348
Thanks!  That did work.  Is this is a general solution?  You specifically mentioned Access -- will this also work with SQL Server (& other ODBC)?
0
 
LVL 10

Accepted Solution

by:
paasky earned 800 total points
ID: 2677217
Happy to help you sniles,

Unfortunately there's no general solution that will work for all ODBC sources. You need to use the specific conversion function of the specific database you're using.

CDate('03/30/00 10:00:00') works with Access.

CONVERT(DateTime, '03/30/00 10:00:00') works with SQL Server

TO_DATE('03/30/00 10:00:00','MM/DD/YY HH24:MI:SS') works with Oracle.

Regards,
Paasky
0
 

Author Comment

by:sniles
ID: 2677337
Thanks again!
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question