Solved

Difference in days between two dates

Posted on 2002-04-25
7
163 Views
Last Modified: 2010-04-04
Hi Folks,

I have two dates.  For example, 07/04/1990 and 25/12/2002 (as you can see, they're in the format of DD/MM/YYYY).  I need to find out how many DAYS have passed since the first date to the second date.

I'm sure there's an easy way of doing this, it's just I can't be bothered thinking about it tonight :)

Thanks,

Stu
0
Comment
Question by:Stuart_Johnson
7 Comments
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 6968161
Oh yeah, if 50 points ain't enough, I'll up it.  I think this is an easy Q., but if it's not, I'm happy to double or triple it.

Stu
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 6968170
convert it to tdatetime
(there are various functions to do this)
and then just take the difference

count of days:= date2-date1;

(sorry no delphi on hand,
therfore no sample,
but so it goes in theory)

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6968176
appendix,
the result will be of double-type,
just use trunc to transform the
result into an integer
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 6

Expert Comment

by:DrDelphi
ID: 6968206
straight from my website (www.drdelphi.com)



var yesterday,today:Tdatetime;
    dayspassed:integer;
begin
today:=strtodate('05/28/1998');
yesterday:=strtodate('05/27/1998');
dayspassed:=(round(today))-(round(yesterday));
showmessage(inttostr(dayspassed));
{Notice that we use the round function here..
This is to get the numbers of DAYS.. if we were looking for the
fractional part of the day as well, we would use a real datatype
for dayspassed and showmessage as FloatTostr(daypassed)}

end;



Good luck!!

0
 
LVL 3

Expert Comment

by:VSF
ID: 6968240
If you are using Delphi6 declare dateutils on your uses clause... on this unit you will find lots of interesting procedures for date handling!
Such as:

function IsInLeapYear(const AValue: TDateTime): Boolean;
function IsPM(const AValue: TDateTime): Boolean;
function IsValidDate(const AYear, AMonth, ADay: Word): Boolean;
function IsValidTime(const AHour, AMinute, ASecond, AMilliSecond: Word): Boolean;
function IsValidDateTime(const AYear, AMonth, ADay, AHour, AMinute, ASecond,
  AMilliSecond: Word): Boolean;
function IsValidDateDay(const AYear, ADayOfYear: Word): Boolean;
function IsValidDateWeek(const AYear, AWeekOfYear,                    {ISO 8601}
  ADayOfWeek: Word): Boolean;
function IsValidDateMonthWeek(const AYear, AMonth, AWeekOfMonth,     {ISO 8601x}
  ADayOfWeek: Word): Boolean;
function WeeksInYear(const AValue: TDateTime): Word;                  {ISO 8601}
function WeeksInAYear(const AYear: Word): Word;                       {ISO 8601}
function DaysInYear(const AValue: TDateTime): Word;
function DaysInAYear(const AYear: Word): Word;
function DaysInMonth(const AValue: TDateTime): Word;
function DaysInAMonth(const AYear, AMonth: Word): Word;
function Today: TDateTime;
function Yesterday: TDateTime;
function Tomorrow: TDateTime;
function IsToday(const AValue: TDateTime): Boolean;
function IsSameDay(const AValue, ABasis: TDateTime): Boolean;


Hope it helps!
VSF
www.victory.hpg.com.br
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 6968315
Hi Meikl,

Thanks heaps :)  Worked a treat.

Thanks to everyone else too for you quick responses!

Stu
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 6968332
DrDelphi,

Meikl's code was the first posted that solved the problem, but it was yours that I actually used.  So, in all fairness, here's some points for you as well.  Thanks a lot!

http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=delphi&qid=20293500

Cheers,

Stu
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 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