Delphi 7 - How to fetch current date for a comparison?

Alright, here's the thing, I need to fetch current date for a comparison on an SQL field.
The SQL field output as: 2011-04-03
How can I fetch current date on that exact format and then make a comparison?
I.e.:
If CurrentDate = qry.FieldByName('datestart').AsDateTime then
//do something

Open in new window


Thanks
John86aAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jimyXCommented:
you can reformat both of them and match them against each other:

If formatdatetime('yyyy-mm-dd',now) = formatdatetime('yyyy-mm-dd',qry.FieldByName('datestart').AsDateTime) then
  //do something
0
Ephraim WangoyaCommented:


if Trunc(Now) = Trunc(qry.FieldByName('datestart').AsDateTime) then
  //do something
0
Ephraim WangoyaCommented:

Compare as integer value much faster than using string
Trunc will remove the time part from the datetime and compare with the exact date only
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

John86aAuthor Commented:
Both codes posted by jimy and wangoya returns this:
 Error
0
jimyXCommented:
Use it this way then:
If formatdatetime('yyyy-mm-dd',now) = qry.FieldByName('datestart').AsString then
  //do something
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ephraim WangoyaCommented:

Is your field a varchar or a real datefield in the database
0
Ephraim WangoyaCommented:

If you are using a varchar to store a date in your table, this will cause you a lot of heart ache in the future not to mention make your queries very slow.

My advice would be to change it to a DateTime field otherwise you have to compare as strings  which is not very good
0
John86aAuthor Commented:
datestart date, not null
dateend date, not null
0
John86aAuthor Commented:
This works, thanks.
0
Ephraim WangoyaCommented:

What database? SQL Server
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.