Solved

Difference in days between two dates

Posted on 2002-04-25
7
165 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
[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
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
Industry Leaders: 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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