Is There a Time Difference Calculator That Works with Delphi?

  • Thread starter irony of truth
  • Start date
  • Tags
    Time
In summary, the conversation is about a person looking for a program that can calculate the time difference between two dates. The person is suggested to write their own script, and another person shares a function they wrote in Delphi that can do the same. The function can also be translated to VB Script for use in web browsers and returns the result in seconds.
  • #1
irony of truth
90
0
Is there a site which has a "program" that allows me to enter two dates and then the program will compute the length of time between these two dates?
 
Computer science news on Phys.org
  • #2
why not sit down and figure that out yourself? heck, you could write a perl script to do that/
 
  • #3
I wrote a function in Delphi that does that. I am not sure if you have Delphi or not. If you really want I can write a VB code and it should be easily transated to VB Script to be used in Web Browsers. By the way, it returns the result in seconds. Here you go. (may get range check error if Date1 > Date2 ^^)

Function SubtractDateTime(Date1, Date2: TDateTime): Extended;
Const
{-Time-}
Millisecond = 0.001;
Second = 1; Seconds = 1;
Minute = 60; Minutes = 60;
Hour = 3600; Hours = 3600;
Day = 86400; Days = 86400;
Week = 604800; Weeks = 604800;
Month = 2629743.83; Months = 2629743.83;
year = 31556926; years = 31556926;
Decade = 315569260; Decades = 315569260;
Century = 3.1556926 * 10e09;
Millenium = 3.1556926 * 10e10;
{-/Time-}
var
Hour1, Min1, Sec1, MSec1 : Word;
Y1, M1, D1: Word;
Hour2, Min2, Sec2, MSec2 : Word;
Y2, M2, D2: Word;
RHour, RMin, RSec, RMSec, RY, RM, RD: Word;
Begin
Try
Result := 0;
DecodeDate(Date1, Y1, M1, D1);
DecodeDate(Date2, Y2, M2, D2);
DecodeTime(Date1, Hour1, Min1, Sec1, MSec1);
DecodeTime(Date2, Hour2, Min2, Sec2, MSec2);
RHour := Hour1 - Hour2;
RMin := Min1 - Min2;
RSec := Sec1 - Sec2;
RMSec := MSec1 - MSec2;
RY := Y1 - Y2;
RM := M1 - M2;
RD := D1 - D2;

Result := Result + RHour * Hour;
Result := Result + RMin * Minute;
Result := Result + RSec * Seconds;
Result := Result + RMSec * MilliSecond;
Result := Result + RY * Year;
Result := Result + RM * Month;
Result := Result + RD * Day;
Except Result := 0;//wtf ^^
End;
End;
 
Last edited:

FAQ: Is There a Time Difference Calculator That Works with Delphi?

What is a "Site with time computations"?

A "Site with time computations" is a website that has features or tools that allow users to perform calculations or measurements related to time. This could include features such as a world clock, countdown timer, or time zone converter.

How accurate are the time computations on these sites?

The accuracy of time computations on these sites can vary depending on the source of the data and the algorithms used. Some sites may use real-time data from atomic clocks, while others may rely on user-generated data. It is important to check the reliability and credibility of the site before relying on its time computations for important tasks.

Can I customize the time computations on these sites?

It depends on the specific site and its features. Some sites may allow users to customize the time format or time zone, while others may not have this option. It is best to explore the site's settings or options to see if customization is available.

Are there any limitations to the time computations on these sites?

Some sites may have limitations on the range of time that can be computed, such as only being able to calculate time within a certain time zone or within a specific date range. It is important to check the site's features and limitations before using it for specific tasks.

Can I use these sites for scientific or professional purposes?

It depends on the credibility and accuracy of the site's time computations. Some sites may be suitable for scientific or professional use, while others may not be reliable enough. It is important to research and verify the accuracy of the site's data and algorithms before using it for important tasks.

Similar threads

Back
Top