Board index » delphi » Comparing two dates in Delphi

Comparing two dates in Delphi

Please help me !
I have two strings : eg. '22/10/1999 12:45:26' and '23/10/1999 17:59:23'
Now I would like to determine what date comes before the other.
How can I do this ? Is there a Delphi function for it or can anyone send me
a routine ?
I'm so confused about the various data types in Delphi ..

Thanks in advance,
Coen De Roover

 

Re:Comparing two dates in Delphi


I think you'll have to convert your datas using encodedate and encodetime
functions. This functions willk return a Tdatetime variable, which you'll
have to compare very basically with the "<" operators..
I used it only for time datas.. i think date works the same way.

Coen De Roover <Coen.De.Roo...@village.uunet.be> a crit dans le message :
80f0ou$2l...@nickel.uunet.be...

Quote
> Please help me !
> I have two strings : eg. '22/10/1999 12:45:26' and '23/10/1999 17:59:23'
> Now I would like to determine what date comes before the other.
> How can I do this ? Is there a Delphi function for it or can anyone send
me
> a routine ?
> I'm so confused about the various data types in Delphi ..

> Thanks in advance,
> Coen De Roover

Re:Comparing two dates in Delphi


JRS:  In article <80f0ou$2l...@nickel.uunet.be> of Thu, 11 Nov 1999
19:05:07 in news:comp.lang.pascal.delphi.misc, Coen De Roover <Coen.De.R

Quote
oo...@village.uunet.be> wrote:
>Please help me !
>I have two strings : eg. '22/10/1999 12:45:26' and '23/10/1999 17:59:23'
>Now I would like to determine what date comes before the other.
>How can I do this ? Is there a Delphi function for it or can anyone send me
>a routine ?
>I'm so confused about the various data types in Delphi ..

Alter your notation to be ISO-8601 compatible, so that the first date is
the sensible '1999-10-22 12:45:26' (YYYY-MM-DD hh:mm:ss), and you can
then just compare the strings.

Failing that, use system routines to convert to TDateTime, and compare.

Too many newsgroups; do you really read all those languages?

Your post will not have appeared on Borland's server as you did not
inject it there; and they don't like cross-posts.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Re:Comparing two dates in Delphi


JRS:  In article <80f0ou$2l...@nickel.uunet.be> of Thu, 11 Nov 1999
19:05:07 in news:comp.lang.pascal.delphi.misc, Coen De Roover <Coen.De.R

Quote
oo...@village.uunet.be> wrote:
>Please help me !
>I have two strings : eg. '22/10/1999 12:45:26' and '23/10/1999 17:59:23'
>Now I would like to determine what date comes before the other.
>How can I do this ? Is there a Delphi function for it or can anyone send me
>a routine ?
>I'm so confused about the various data types in Delphi ..

Alter your notation to be ISO-8601 compatible, so that the first date is
the sensible '1999-10-22 12:45:26' (YYYY-MM-DD hh:mm:ss), and you can
then just compare the strings.

Failing that, use system routines to convert to TDateTime, and compare.

Too many newsgroups; do you really read all those languages?

Your post will not have appeared on Borland's server as you did not
inject it there; and they don't like cross-posts.

-

Group it.comp.delphi removed; it has a cross-bot.
--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Re:Comparing two dates in Delphi


JRS:  In article <80f0ou$2l...@nickel.uunet.be> of Thu, 11 Nov 1999
19:05:07 in news:comp.lang.pascal.delphi.misc, Coen De Roover <Coen.De.R

Quote
oo...@village.uunet.be> wrote:
>Please help me !
>I have two strings : eg. '22/10/1999 12:45:26' and '23/10/1999 17:59:23'
>Now I would like to determine what date comes before the other.
>How can I do this ? Is there a Delphi function for it or can anyone send me
>a routine ?
>I'm so confused about the various data types in Delphi ..

Alter your notation to be ISO-8601 compatible, so that the first date is
the sensible '1999-10-22 12:45:26' (YYYY-MM-DD hh:mm:ss), and you can
then just compare the strings.

Failing that, use system routines to convert to TDateTime, and compare.

Too many newsgroups; do you really read all those languages?

Your post will not have appeared on Borland's server as you did not
inject it there; and they don't like cross-posts.

--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Re:Comparing two dates in Delphi


Quote
Alistair Allen <Alistair.Al...@wbci.freeserve.co.uk> wrote:
> Try this:

> const
>   c_date1 = '22/10/1999 12:45:26';
>   c_date2 = '23/10/1999 17:59:23';

> begin
>   if StrToDateTime(c_Date1) = StrToDateTime(c_Date2) then
>     Self.Caption := 'Equal'
>   else if StrToDateTime(c_Date1) > StrToDateTime(c_Date2) then
>     Self.Caption := 'Date 1 is greater than Date 2'
>   else
>     Self.Caption := 'Date 1 is less than Date 2';
> end;

Ah... clever!

You make sure you call the same procedure twice, just to make the program
run slower?
Hah :))

 - Frode Greger
    (fr...@netconnect.no)

Re:Comparing two dates in Delphi


JRS:  In article <80f0ou$2l...@nickel.uunet.be> of Thu, 11 Nov 1999
19:05:07 in news:comp.lang.pascal.delphi.misc, Coen De Roover <Coen.De.R

Quote
oo...@village.uunet.be> wrote:
>Please help me !
>I have two strings : eg. '22/10/1999 12:45:26' and '23/10/1999 17:59:23'
>Now I would like to determine what date comes before the other.
>How can I do this ? Is there a Delphi function for it or can anyone send me
>a routine ?
>I'm so confused about the various data types in Delphi ..

Alter your notation to be ISO-8601 compatible, so that the first date is
the sensible '1999-10-22 12:45:26' (YYYY-MM-DD hh:mm:ss), and you can
then just compare the strings.

Failing that, use system routines to convert to TDateTime, and compare.

Too many newsgroups; do you really read all those languages?

Your post will not have appeared on Borland's server as you did not
inject it there; and they don't like cross-posts.

-

Group it.comp.delphi removed; it has a cross-bot.
--
? John Stockton, Surrey, UK.  j...@merlyn.demon.co.uk   Turnpike v4.00   MIME. ?
 <URL: http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
 <URL: ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ;
 <URL: http://www.merlyn.demon.co.uk/clpb-faq.txt> Pedt Scragg: c.l.p.b. mFAQ.

Other Threads