Solved

DateTime and TTable  filtering

Posted on 2003-10-30
3
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Performance of SQL statement 37 143
Wincontrol not (correctly) drawn 15 53
MS Access from Delphi 31 97
Delphi TListView and TEdit (Select item and input into TEdit) 10 76
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

736 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