Solved

Comparing database dates with a Date Filter

Posted on 2008-10-15
3
813 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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
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 NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now