Solved

SQL Expression to get current date

Posted on 2002-07-19
5
269 Views
Last Modified: 2010-04-04
I'm trying to run a query in a QReport that selects rows based on the current date and time, as in

SELECT * FROM Calls
WHERE ((DeadlineDate < ??CurrentDate??) OR ((DeadlineDate = ??CurrentDate??) AND (DeadlineTime < ??CurrentTime??))

Any ideas as to what should go between the ??'s? I've tried things like GetDate() and SYSDATE to no avail.

Cheers
0
Comment
Question by:riccohb
[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
  • 2
5 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7164821
SELECT * FROM Calls
WHERE ((DeadlineDate < :Date1) OR ((DeadlineDate = :Date2) AND (DeadlineTime < :Time1))

depending of the type of fields, i guess its date-type

query1.close;
query1.parambyname('Date1').AsDateTime := Trunc(now);
query1.parambyname('Date2').AsDateTime := Trunc(now);
query1.parambyname('Time').AsDateTime := Frac(now);
query1.open;

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7164823
oops, :time should be :time1 ;-)
0
 

Author Comment

by:riccohb
ID: 7164965
Thanks for that Meikl, but I'm getting a 'type mismatch in expression'. It works fine if I leave out the Time part of the expression/code. The table I'm working on was created in Database Desktop. The date fields are type 'Date' and the time field is type 'Time'.

Can you help?

I'm very grateful for your time.
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 7164980
hmm maybe this change helps

instead of
query1.parambyname('Time').AsDateTime := Frac(now);

use
query1.parambyname('Time').AsTime := Frac(now);
or also
query1.parambyname('Time').AsTime := now;

hope this helps

meikl ;-)

0
 

Author Comment

by:riccohb
ID: 7165047
Perfect. Thanks,
0

Featured Post

Independent Software Vendors: 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

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…
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…
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…

738 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