Function to calculate how many whole months between two specified dates.

 

Syntax

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

 

Parameters and return values

Параметр

Type

Value

dNow

double

first value of the date and time;

dtThen

double

second value of the date and time.

 

Function result

Returns the approximate number of months. Date order does not matter, the answer is always >=0. One month has 30.4375 days approximately. The fractional months are ignored.

 

Example

var
  dtFrom, dtNow: double;
begin
  dtFrom := EncodeDateTime(2000, 1, 1, 1, 0, 0, 0);
  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('Result: ' + IntToStr(MonthsBetween(dtFrom, dtNow)), '');
end.

Script work result

[18:05:11] (Log "MonthsBetween"): From date: 01.01.2000 01:00:00

[18:05:11] (Log "MonthsBetween"): To date: 07.05.2016 18:05:11

[18:05:11] (Log "MonthsBetween"): Result: 198

 

See also
EncodeDate
IntToStr
mLogScript

Now