Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in seconds between two TDateTime variables

Tags:

delphi

Looking for a code sample that returns the difference in seconds between two TDateTime values. Specifically, I am trying to compare two TDateTime values and if greater than a second threshold it will run a specific method.

Thanks!

like image 293
Jeff Cope Avatar asked Mar 20 '12 15:03

Jeff Cope


People also ask

How do you find the difference in seconds in Python?

To get the difference between two-time, subtract time1 from time2. A result is a timedelta object. The timedelta represents a duration which is the difference between two-time to the microsecond resolution. To get a time difference in seconds, use the timedelta.

How can you find the difference in time between two datetime objects time_1 and time_2?

Subtracting the later time from the first time difference = later_time - first_time creates a datetime object that only holds the difference.

How do I get the difference between two datetime objects in python?

timedelta() method. To find the difference between two dates in Python, one can use the timedelta class which is present in the datetime library. The timedelta class stores the difference between two datetime objects.


2 Answers

Try the SecondsBetween function which is part of the DateUtils unit.

Sample of use

SecondsBetween(Now, IncSecond(Now,10))  

Will return 10

like image 147
RRUZ Avatar answered Oct 22 '22 01:10

RRUZ


Call SecondsBetween from the DateUtils unit. For example:

Assert(SecondsBetween(MyAnswer, RRUZsAnswer)=7) 
like image 24
David Heffernan Avatar answered Oct 22 '22 01:10

David Heffernan