Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Get the number of days between 2 TDateTime structures

Posted on 1999-01-27
Medium Priority
167 Views
Has anybody some code handy to get the number of days that had passed between two TDateTime structures?
0
Question by:jonnyfive
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 3
• 3

LVL 20

Accepted Solution

Madshi earned 200 total points
ID: 1363542
Very simple. Just look at the difference.

dt2-dt1 = 2.5    =>  two and a half days past by...

0

LVL 5

Expert Comment

ID: 1363543
Sure, just subtract 1 from the other.  Like This

function ElapsedDays(D1, D2: TDateTime): integer;
begin
Result := Round(abs(D1 - D2));
end;
0

LVL 5

Expert Comment

ID: 1363544
Oops, Sorry Madshi - Posted at same time :)

Heath
0

LVL 5

Expert Comment

ID: 1363545
BTW - I should have put Trunc instead of Round. Wasnt thinking

Heath
0

Author Comment

ID: 1363546
Besides that I'm wondering if you guys ever sleep, I'm very impressed with the quick and excellent solutions I got from you. Thanks a lot and points well earned :-))

0

LVL 20

Expert Comment

ID: 1363547
:-)

Am sitting at work right now. So I check my eMails and EE every hour. It's good that my boss works two streets from here...  :-)

0

LVL 20

Expert Comment

ID: 1363548
Hi Heath, hmmm. If I would have written a little function (like you did), you would have probably been faster than I. So I'm sorry for taking the points away...    :-)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
###### Suggested Courses
Course of the Month11 days, 15 hours left to enroll

#### 730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.