Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Days passed since..

Posted on 2004-04-27
8
Medium Priority
?
298 Views
Last Modified: 2010-04-05
I need a function to give me how many days have passed
since a given data. It has to keep in mind about different
data formats.

Thanks.
0
Comment
Question by:bryan7
[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
8 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 2000 total points
ID: 10926022
>It has to keep in mind about different data formats.

just transform it into tdatetime

function DaysBetween(d1,d2 : TDateTime) : Integer;
begin
  result := Abs(trunc(d1-d2));
end;

meikl ;-)

0
 
LVL 12

Expert Comment

by:Ivanov_G
ID: 10926065

  yep, kretzschmar is right, but let me add something... you don't need the Abs function because ...

  TDateTime is real number. The integer part represent the days after 12/30/1899. So trunc(d1-d2) will give you the number of days... This can me negative value ...
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10926088
>This can me negative value ...

i added abs, to avoid negative values :-))
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 23

Expert Comment

by:Ferruccio Accalai
ID: 10926103
guys the DaysBetween function already exists in DateUtils.pas that gives the integer value of the difference between 2 dates...

also it contain DaySpan function that gets the difference included the frac part of entire day...

from Delphi help:

Call DaysBetween to obtain the difference, in days, between two TDateTime values.

DaysBetween counts only whole days. Thus, DaysBetween reports the difference between Dec 31, 1999 11:59 PM and Jan 1, 2000 11:58 PM as 0 because the difference is one minute short of an entire day.

Call DaySpan to obtain the difference, in days, between two TDateTime values. Unlike the DaysBetween function, which only counts whole days, DaySpan reports incomplete days as a fraction of an entire day.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10926109
i know, f68 :-))
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10926111
just to say, that DateUtils.pas is not on all delphi versions available
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 10926129
function DaySpan(d1,d2 : TDateTime) : Double;
begin
  result := Abs(d1-d2);
end;

meikl ;-)
0
 
LVL 3

Author Comment

by:bryan7
ID: 10926141
Ahh thanks, that was easier than I thought eheh.
EncodeTime will do the rest. Btw my delphi5 enterprise
doesn't include that unit :(

grats kretzs on the first working answer

Thanks all for the help :)
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

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

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

Join & Ask a Question