Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 2 of 2 total
Thread substracting dates
Sat, Aug 19 2017 12:33 PMPermanent Link

Paul Waegemans

IMS bvba

Avatar

I have 2 calendars and I want the number of days between the 2 selected dates in a counter (integer)

counter:=calendar2.SelectedDate-calendar1.SelectedDate;

When I want to show the number of days:

Showmessage(IntToStr(counter));

the number of days is not shown and the system is no longer reacting.

What am I missing?

Paul.
Sat, Aug 19 2017 1:07 PMPermanent Link

Raul

Team Elevate Team Elevate

On 8/19/2017 12:33 PM, Paul Waegemans wrote:

Paul

> I have 2 calendars and I want the number of days between the 2 selected dates in a counter (integer)
> counter:=calendar2.SelectedDate-calendar1.SelectedDate;
> When I want to show the number of days:

SelectedDate is a TimeDate type variable and as per EWB manual TimeDate
represents milliseconds (since 1970) so your "counter" at this point is
just milliseconds between the 2 dates and not days.

If you want actual days then you'd need to also divide it by
"milliseconds per day" which is 86400000 (24 hours x 60 min x 60sec x
1000 msec).

> Showmessage(IntToStr(counter));
> the number of days is not shown and the system is no longer reacting.
> What am I missing?

Showmessage is modal and so it requires you to click OK

You did not show actual code so i'm going to assume you are doing
something else after calling showmessage (like showing/hiding forms or
such which might hide the showmessage dialog).

This works just fine here and shows results as expected:

procedure TForm1.Button1Click(Sender: TObject);
var
   counter:integer;
begin
   counter := (Calendar2.selecteddate-Calendar1.selecteddate) div 86400000;
   showmessage(inttostr(counter));
end;


Raul
Image