Jeff Cope
Jeff Cope

Reputation: 791

Difference in seconds between two TDateTime variables

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!

Upvotes: 29

Views: 49929

Answers (2)

RRUZ
RRUZ

Reputation: 136431

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

Sample of use

SecondsBetween(Now, IncSecond(Now,10)) 

Will return 10

Upvotes: 53

David Heffernan
David Heffernan

Reputation: 613441

Call SecondsBetween from the DateUtils unit. For example:

Assert(SecondsBetween(MyAnswer, RRUZsAnswer)=7)

Upvotes: 26

Related Questions