Solved

Comparing database dates with a Date Filter

Posted on 2008-10-15
3
815 Views
Last Modified: 2013-11-23
Hi,
I'm using the following block of code to filter mysql records.

        mysqltableClients.Filtered  := False;
        mysqltableClients.Filter    := 'contractor = '      + QuotedStr(contractor.text) +
                                                'AND assignedto = ' + QuotedStr(un.text) +
                                                   'AND cstatus = '    + QuotedStr('UNSIGNED') +
                                                   'AND status <> '    + QuotedStr('INVALID') +
                                                   'AND status <> '    + QuotedStr('NFC') +
                                                   'AND status <> '    + QuotedStr('COMPLETE') +
                                                   'AND status <> '    + QuotedStr('FADS') +
                                                   'AND lm < 4'           +
                                                   'AND apptdate = '  + QuotedStr('12/31/1899') +
                                                   'AND date > '         + QuotedStr('03/20/2008');
        mysqltableClients.Filtered  := True;

the problem is the last two comparisons.... apptdate and date
I am getting no records, when I know there are records that meet these conditions.

Isn't there a better way to compare date fields with static dates ?
What am I doing wrong?

Thanks in advance
0
Comment
Question by:delphimon
3 Comments
 
LVL 14

Expert Comment

by:SteveBay
ID: 22724978
Just a guess: Depending upon the database you are using appdate may in fact be equal to '12/31/1899 12:00'
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 22725601
Honestly, with that many individual filter components, I would do it in a query instead.  If you have a large table your filter operation could be horridly slow.  If you need to know more about using a query in this instance I would need to know which database you are using.  It may also help to know how many records you have.
0
 

Accepted Solution

by:
delphimon earned 0 total points
ID: 22835808
Well, I ended up putting my date into an edit field like this...
apptdate.text := '12/31/1899';

and changed the code as follows:
Was: 'AND apptdate = '  + QuotedStr('12/31/1899')
Changed to: 'AND apptdate = '  + QuotedStr(apptdate.text)

And it works...
I really don't like this work around, but it works... ;-)
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

770 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