Solved

How to find the difference between 2 dates?

Posted on 1998-11-10
1
256 Views
Last Modified: 2010-04-16
I would like to know how can u get the difference between two given dates (using the getdate functions) , like u can subtract them directly in Delphi?
0
Comment
Question by:xkuma
1 Comment
 
LVL 3

Accepted Solution

by:
vikiing earned 100 total points
ID: 1216052
You have to convert back and forth to/from "julian" format.

Julian format gives you a unique continuous number, in such a way that differences of one day in the date, implies 1 unit difference in julian.

Look at this:

{ Date comes specified as year, month, day }
Function DateToJul(Y, M, D: integer): longint;
Var
        x: single;
        m1, m2: integer;
Begin
        If m<3 then m1 := -1 else m1 := 0;
        If m>2 then m2 := -1 else m2 := 0;

        DateToJul:=Trunc((Y+m1)*365.25)+
                   Trunc((M-13*m1-m2)*30.6001)+D
end;


With that, you can do:

Var
       diff: longint;

Begin
       Diff:=DateToJul(1998, 11, 10) -    { Today's date }
             DateToJul(1975, 5, 31)       { 5/31/75 }

"Diff" will contain the amount of days of difference between those two dates.

Of course, the counterpart (Jul-to-Date) also exists, but I think this is enough to solve your problem.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple JPEG trim operation with delphi 8 453
Twsocket as Twsocketserver 6 1,629
Pascal code for reading registry 1 349
Delphi need modify hand cursor windows 4 558
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

12 Experts available now in Live!

Get 1:1 Help Now