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!
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.
Subtracting the later time from the first time difference = later_time - first_time creates a datetime object that only holds the difference.
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.
Try the SecondsBetween
function which is part of the DateUtils unit.
Sample of use
SecondsBetween(Now, IncSecond(Now,10))
Will return 10
Call SecondsBetween
from the DateUtils
unit. For example:
Assert(SecondsBetween(MyAnswer, RRUZsAnswer)=7)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With