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?
 
jimyXCommented:
Use it this way then:
If formatdatetime('yyyy-mm-dd',now) = qry.FieldByName('datestart').AsString then
  //do something
0
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
 
John86aAuthor Commented:
Both codes posted by jimy and wangoya returns this:
 Error
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.