Gives the whole number of days between 2 dates DateUtils unit
 function DaysBetween ( const ToDate, FromDate : TDateTime ) : Integer;
The DaysBetween function subtracts the FromDate from the ToDate, returning the number whole days difference.
The time value of each date is taken account of - only whole 24 hour chunks are counted as whole days.
A whole day does not have to start at 00:00:00.
Related commands
DaysInAMonth Gives the number of days in a month
DaysInAYear Gives the number of days in a year
DaySpan Gives the fractional number of days between 2 dates
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : Find the days difference between two date+time values.
  fromdate, toDate : TDateTime;

  // Set up our date variables
  fromDate := EncodeDateTime(2000, 02, 26, 10, 0, 0, 0);
  toDate   := EncodeDateTime(2000, 02, 29,  9, 0, 0, 0);

  // Display these dates and the days between them
  ShowMessage('From date = '+DateTimeToStr(fromDate));
  ShowMessage('To   date = '+DateTimeToStr(toDate));
  ShowMessage('Whole days difference = '+
              IntToStr(DaysBetween(toDate, fromDate))+' days');
Show full unit code
   From date = 26/02/2000 10:00:00
   To   date = 29/02/2000 09:00:00
   Whole days difference = 2 days
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page