 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Colin White Guest
|
Posted: Thu Dec 21, 2006 5:02 pm Post subject: getting samedate function to work |
|
|
I'm simply trying to compare 'today's' date with a predetermined date. I've used:
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=datetostr(date);
if samedate(20/12/2006,date) then edit2.text:='same date' else edit2.text:='dif dates';
end;
Even though edit1.text shows exactly 20/12/2006, I can't get the two to equal up.
I've tried other methods such as
if date = 20/12/2006 then ....
or comparedates but I'm geting nowhere.
Have I done something really stupid?!
Thanks
Col. |
|
| Back to top |
|
 |
Matt M Guest
|
Posted: Thu Dec 21, 2006 9:58 pm Post subject: Re: getting samedate function to work |
|
|
Colin White used his keyboard to write :
| Quote: | I'm simply trying to compare 'today's' date with a predetermined date. I've
used:
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=datetostr(date);
if samedate(20/12/2006,date) then edit2.text:='same date' else
edit2.text:='dif dates'; end;
Even though edit1.text shows exactly 20/12/2006, I can't get the two to equal
up. I've tried other methods such as
if date = 20/12/2006 then ....
or comparedates but I'm geting nowhere.
Have I done something really stupid?!
Thanks
Col.
|
Well since DateTime is a int double type, you can use it as a regular
number for comparisons. (Output Date to a debug line using FloatToStr
and you'll see that it is a number).
Keeping Date as it is (a number internally), convert your target date
of December 20, 2006 from a string into a date using:
function EncodeDate ( const Year, Month, Day : Word ) : TDateTime;
MyDate := EndocdeDate(2006,12,20);
And to check:
if MyDate = Date then
begin
//the dates match
end; |
|
| Back to top |
|
 |
Rob Kennedy Guest
|
Posted: Thu Dec 21, 2006 11:25 pm Post subject: Re: getting samedate function to work |
|
|
Colin White wrote:
| Quote: | I'm simply trying to compare 'today's' date with a predetermined date. I've used:
procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.text:=datetostr(date);
if samedate(20/12/2006,date) then edit2.text:='same date' else edit2.text:='dif dates';
end;
|
Delphi doesn't have any way of writing a TDate literal, except as a
floating-point value that looks nothing like the date it represents. The
value you've written in the SameDate call is really just twenty divided
by twelve divided by two thousand six.
| Quote: | Even though edit1.text shows exactly 20/12/2006, I can't get the two to equal up.
|
Well, you took the edit-box text, which was a string, and applied the
StrToDate function to it. You could try doing the same with your other
date: Write it as a string, and then convert it.
You can also use the EncodeDate function to create a TDate value from
the three integer values.
You can also just call the Date function, which will return today's date.
--
Rob |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|