Solved

DateTime and TTable  filtering

Posted on 2003-10-30
3
255 Views
Last Modified: 2010-04-03
   s:='HOSPITAL='''+IntToStr(ComboBox1.ItemIndex)+'''';
    s:= s + ' and DATA >='''+ DateToStr(StartD.Date) + ''' and DATA <='''+ DateToStr( EndD.Date)+''' ';
    Table1.Filter := s;

Using upside code I get a filtering just after day, but I wish to filter by day, month and year. Where I wrong ?
0
Comment
Question by:ginsonic
3 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 150 total points
ID: 9655914
if StartD.Date and EndD.Date are results from TDateTimePickers,
then there is a timefragment included

try following change


    s:= s + ' and DATA >='''+ DateToStr(Trunc(StartD.Date)) + ''' and DATA <='''+ DateToStr(trunc(( EndD.Date))+''' ';

on the other hand, datecompares are also pending on regional settings

meikl ;-)
   
0
 
LVL 17

Assisted Solution

by:geobul
geobul earned 100 total points
ID: 9656332
Hi,

What is the type of your DATA field - date or string? In both cases I would recommend FormatDateTime('your database date format', StartD.Date) instead of DateToStr.

Regards, Geo
0
 
LVL 4

Expert Comment

by:SurferJoe
ID: 9657584
Geo is correct FomatDate is a much stronger solution.

Otherwise with some date types you can end up with long dates like “2003-07-16 02:21:45.192” which do not evaluate as expected.


Excerpt
        QueryString := 'where LOGINDATE >= ' + #39 + FormatDateTime('mm/dd/yyyy', (Date - 185)) + #39 +
          ' and LOGINDATE <= ' + #39 + FormatDateTime('mm/dd/yyyy', (Date + 185)) + #39


0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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