Comparing TDates???

I have a serious problem!!! I need to compare two dates of TDate, but can't seem to make it work :-(

For instance I tried this:

procedure TForm1.Button1Click(Sender: TObject);
begin
  If dateTimePicker1.Date = dateTimePicker2.Date then
    Showmessage('The same')
  else
    showmessage('not the same');
end;

And no matter if I gave them the same dates or different dates, the answer was 'Not the same' :-(



I also tried to typecast into double, but also with no luck.

Please help!!! It is very important for me since it is a big part of a schoolproject which deadline is coming closer in an eksponential rate (or so it seems :-)

Thanks
Retep
retepAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
JoeBoothConnect With a Mentor Commented:
The date value actually holds both a date and time portion.  If you are only interested in the date, use

TRUNC(DateTimePicker1.Date) =
TRUNC(DateTimePicker2.Date)

This tells Delphi to ignore the time portion of the date variable.
0
 
IndefreiCommented:
try something like
Label1.Caption := DateToStr(dateTimePicker1.Date);
Label2.Caption := DateToStr(dateTimePicker2.Date);
and compare the labels
(yet not tested)
Indi
0
 
retepAuthor Commented:
Thanks JoeBooth. Excatly what I was looking for! Now I'm very happy, and can get on with my project... :-)

Indefrei>> Before I posted this question I tried DateToStr, but soon discovered that using the DateToStr solution was not very Y2K-proof, since it only uses two digits...

Thanks to both of U.
Retep

0
All Courses

From novice to tech pro — start learning today.