Solved

Difference in days between two dates

Posted on 2002-04-25
7
159 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now