?
Solved

Difference in days between two dates

Posted on 2002-04-25
7
Medium Priority
?
168 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 200 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
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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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 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 Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

719 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