Solved

SQL and dates

Posted on 1998-07-21
8
147 Views
Last Modified: 2010-04-04
Hi All,

I have a question relating to SQL and dates.  I have a database which contains a number of items.  Each time the program is executed, the database is checked to see if an item will be out of date within the next 21 days. The problem that I am having is this:  the query is not returning any items which exceed the date given.

Here is basically what I am doing:


SQL Statement (within the query):

Select * from ALL_ITEMS
where :ThisDate > Items_Date


the :ThisDate parameter is typed as a DateTime, as is the Items_Date


The procedure I am using to check these items is:

Procedure TMain.CheckDates;
Var Check_Date: TDateTime;

begin
   Check_Date := DATE + 21;  
   ItemQuery.Active := False;
   ItemQuery.ParamByName('ThisDate').asDataTime := ChecK_Date;
   ItemQuery.Active := True;
End;

Ok, from this, I get no records in the query at all.

Any ideas at all.  The program is in very early development stages, therefore, I am quite happy to change anything to get this thing working properly!

Thanks for any help you can provide.

Stuart.

If you have any examples, please forward them to jonstu@acay.com.au if possible.

OH!  And as a last second thought, any ideas how to make a Paradox database use full dates??  ie DD/MM/YYYY??.
0
Comment
Question by:Stuart_Johnson
8 Comments
 
LVL 10

Expert Comment

by:Jacco
ID: 1358322
What type of database do you use?

It is better to use Open and close:

ItemQuery.Close;
ItemQuery.ParamByName('THISDATE').AsDateTime := Check_Date;
ItemQuery.Open;

But your example should work as well.

How did you check if the Query returns data?

To make an easy check:
Add a TDataSource and set its DataSet property to ItemQuery
Add a DBGrid and set its DataSource property to the DataSource you just added.

If the Query is opened the data should automatically appear in the DBGrid.

Regards Jacco
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1358323
Hi Jacco,

Thats basically how I am doing it now.  I just dont get any data.  I'll keep trying.  Thanks for the comment.  Any more suggestions??

Stu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1358324
Edited text of question
0
 
LVL 3

Expert Comment

by:vladika
ID: 1358325
Try this
just interchange :ThisDate and Items_Date as

select * from ALL_ITEMS  where Items_Date<:ThisDate

0
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.

 
LVL 2

Expert Comment

by:kjteng
ID: 1358326
I have tried your code. It works fine on my pc.(after changing   ItemQuery.ParamByName('ThisDate').asDataTime to
  ItemQuery.ParamByName('ThisDate').asDatETime)

May be there is really no record dated after 21 from today?
Or may be what you actually want is the result for
   :ThisDate < Items_Date

"to make a Paradox database use full dates"
1. changes the short date format in your Windows Control Panel International dialog box.
 OR
2. put the following line in you program:
     shortDateformat:= 'dd/mm/yyyy';

Hope this help


0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1358327
kjteng,

Can you please repost this as an answer for me.  I'll test this once I get home.  I think I have made a mistake :)  I didnt realise that  you could use the ShortDateFormat though.  Thanks for pointing that out.

Stuart.
0
 
LVL 2

Accepted Solution

by:
kjteng earned 100 total points
ID: 1358328

     changing   ItemQuery.ParamByName('ThisDate').asDataTime to
       ItemQuery.ParamByName('ThisDate').asDatETime)

     May be there is really no record dated after 21 from today?
     Or may be what you actually want is the result for
        :ThisDate < Items_Date

     "to make a Paradox database use full dates"
     1. changes the short date format in your Windows Control Panel International
     dialog box.
      OR
     2. put the following line in you program:
          shortDateformat:= 'dd/mm/yyyy';

     Hope this help
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1358329
Hi kjteng,

OK, I have it working now, thanks very much.  That ShortDateFormat constant would be very handy if it was documented :)  I couldnt find anything in any of the help files or examples relating to it at all.

The program is working just fine.  Thank you.  The points are well earnt!

Stuart.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

17 Experts available now in Live!

Get 1:1 Help Now