Solved

DateTime and TTable  filtering

Posted on 2003-10-30
3
252 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
JSON on ISAPI REST Server using Delphi 2 210
delphi prevent click fast 2 166
FMX enumerated colours 2 72
Run video youtube webbrowse 10 45
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…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

757 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

19 Experts available now in Live!

Get 1:1 Help Now