Date

I have two date, for example dateTimePicker1.date  and datetimepicker2.date, I want the difference, could you help me? ......I need the days
chiroAsked:
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.

chiroAuthor Commented:
Edited text of question.
0
KECommented:
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
KECommented:
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
Starting with Angular 5

Learn the essential features and functions of the popular JavaScript framework for building mobile, desktop and web applications.

chiroAuthor Commented:
Edited text of question.
0
rwilson032697Commented:
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
EdHillmannCommented:
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

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KECommented:
Excuse me mr. Ed :-x
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.