I have two dates: 1. Feb 1, 2013 2. Now. So there is a difference of 2 days in between 2 dates. How can I get this difference of days in delphi programmatically?
4
votes
2 Answers
10
votes
2
votes
The TDateTime
is a float format where the integer part represents the number of days while the zecimal part represents the time (as a fraction of 24h).
So if you want to get a date that's tow days from today, you just add 2
to the original. If you you've got two dates and you want to compute the distance in days, use DaysBetween
as Andreas suggests.
Example:
var D:TDateTime;
begin
D := EncodeDate(2013, 2, 1);
D := D + 2; // Adds two days.
end;
You can also use the IncDay
function from DateUtils
to do the same; Some would say it's more readable:
D := IncDay(D, 2);
"Date/Time manipulation - friendly countdown string"
. - LU RD