Function to calculate how many whole days between two dates.

 

Syntax

function DaysBetween(dNow, dThen: double): integer;

 

Parameters and return values

Parameter

Type

Value

dNow

double

first value of the date and time;

dtThen

double

second value of the date and time.

 

Function result

The number of whole days. The function always returns a positive result, it means, the parameters can be interchangeable (it does not matter if the first parameter is the greater or less).

 

Example


var
  dtFrom, dtNow: double;
begin
  // first day of 2000 year
  dtFrom := EncodeDateTime(2000, 1, 1, 1, 0, 0, 0);
  // and now
  dtNow  := Now;
  // print this dates
  mLogScript('From date: ' + FormatDateTime('mm.dd.yyyy hh:nn:ss', dtFrom), '');
  mLogScript('To date: ' + FormatDateTime('mm.dd.yyyy hh:nn:ss', dtNow), '');
  
  mLogScript('Whole days: ' + IntToStr(DaysBetween(dtFrom, dtNow)), '');
end.


Script work result

[20:10:26] (Log "DaysBetween"): From date: 01.01.2000 01:00:00

[20:10:26] (Log "DaysBetween"): To date: 07.03.2016 20:10:26

[20:10:26] (Log "DaysBetween"): Whole days: 6028

 

See also

EncodeDate
IntToStr
mLogScript

Now