• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

Days passed since..

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
bryan7
Asked:
bryan7
1 Solution
 
kretzschmarCommented:
>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
 
Ivanov_GCommented:

  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
 
kretzschmarCommented:
>This can me negative value ...

i added abs, to avoid negative values :-))
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
Ferruccio AccalaiSenior developer, analyst and customer assistance Commented:
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
 
kretzschmarCommented:
i know, f68 :-))
0
 
kretzschmarCommented:
just to say, that DateUtils.pas is not on all delphi versions available
0
 
kretzschmarCommented:
function DaySpan(d1,d2 : TDateTime) : Double;
begin
  result := Abs(d1-d2);
end;

meikl ;-)
0
 
bryan7Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now