BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

getting samedate function to work

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Students
View previous topic :: View next topic  
Author Message
Colin White
Guest





PostPosted: Thu Dec 21, 2006 5:02 pm    Post subject: getting samedate function to work Reply with 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.
Back to top
Matt M
Guest





PostPosted: Thu Dec 21, 2006 9:58 pm    Post subject: Re: getting samedate function to work Reply with quote



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





PostPosted: Thu Dec 21, 2006 11:25 pm    Post subject: Re: getting samedate function to work Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Students All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.