Solved

How to find the difference between 2 dates?

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article describes how to import Lotus Notes Contacts into Outlook 2016, 2013, 2010 and 2007 etc. with a few manual steps. You can easily export and migrate Lotus Notes contacts into Microsoft Outlook without having to use any third party tools.
This article is in regards to the Cisco QSFP-4SFP10G-CU1M cables, which are designed to uplink/downlink 40GB ports to 10GB SFP ports. I recently experienced this and found very little configuration documentation on how these are supposed to be confi…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

630 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