Solved

How to find the difference between 2 dates?

Posted on 1998-11-10
1
253 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Moving applications to the cloud or switching services to cloud-based ones, is a stressful job.  Here's how you can make it easier.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
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: …

746 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

9 Experts available now in Live!

Get 1:1 Help Now