Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to find the difference between 2 dates?

Posted on 1998-11-10
1
Medium Priority
?
290 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 400 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Ranking ecommerce websites is a vital process. You need to have a strong SEO (Search Engine Optimization) strategy. If you don’t have one, you are losing out on brand impressions, clicks and sales. Check this guide on how to improve website traffic …
Following on from our article on "The Murky World of Consent and opt in", we thought we would issue some helpful guidance, not only on consent itself but knowing what information you are capturing, what you are doing with this data and how you can p…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

877 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