Solved

DateTime and TTable  filtering

Posted on 2003-10-30
3
257 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:Greg Rowland
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

735 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