Solved

comparing a datetime in WHERE clause inMFC CRecordset

Posted on 2000-03-30
6
417 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
  • 3
  • 2
6 Comments
 
LVL 142

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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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 200 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

803 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