# Date

I have two date, for example dateTimePicker1.date  and datetimepicker2.date, I want the difference, could you help me? ......I need the days
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Author Commented:
Edited text of question.
0
Commented:
I asume that you want the difference in days ?

This gives the difference in days:

function DayDifference( d1, d2: TDateTime ): Integer;
begin
Result := Trunc( d1 - d2 );
end;

begin
DayDif := DayDifference( DateTimePicker1.date, DateTimePicker2.date );
end;

Regards
0
Commented:
Sorry this is better as it will always return a possitive number.

function DayDifference( d1, d2: TDateTime ): Integer;
begin
Result := Abs(Trunc( d1 - d2 ));
end;

0
Author Commented:
Edited text of question.
0
Commented:
Hmm... this might be closer to what chiro wants (perhaps :-):

function DayDifference( d1, d2: TDateTime ): Integer;
begin
Result := Abs(Trunc(d1) - trunc(d2) ));
end;

IE: This says that the diff between 3Pm Monday and 9AM Tuesday is one day - it is the number of calender days between 'dates'.

Cheers,

Raymond.

0
Commented:
TDateTime fields are floating point numbers, with the whole number portion representing the date and the decimal portion representing the time.

Because they're numbers, you can do basic arithmetic to get the difference between dates.  If you ignore the decimal portion, you will get the day difference between the two dates.

I'll leave it to you if you want to have a 0 or 1 value if the DateTime difference is actually less than 24 hours.  I'll also let you determine if you want negative values or not.  There are cases when you'd want either of these results. :)

Ed
0

Experts Exchange Solution brought to you by