Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to find the difference between 2 dates?

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
What we learned in Webroot's webinar on multi-vector protection.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

718 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