DelphiDabbler Code Snippets Database

Snippet Selection

The following snippets from the Code Snippets Database have been requested.

AddDays

Adds the number of days, Days, to the given date, DateTime and returns the result. To subtract days, pass a negative value for Days.

function AddDays(const DateTime: TDateTime; const Days: Integer): TDateTime;
begin
  Result := DateTime + Days;
end;

DayOfYear

Returns the day of the year for the given date.

function DayOfYear(const DT: TDateTime): Integer;
begin
  Result := Trunc(DT - DateYearStart(DT)) + 1;
end;

DiffDays

Returns the whole number of days separating two given dates.

function DiffDays(const DT1, DT2: TDateTime): Integer;
begin
  Result := Trunc(DT1 - DT2);
end;

IsFriday

Checks if the given date is a Friday.

function IsFriday(const DT: TDateTime): Boolean;
begin
  Result := SysUtils.DayOfWeek(DT) = 6;
end;

IsMonday

Checks if the given date is a Monday.

function IsMonday(const DT: TDateTime): Boolean;
begin
  Result := SysUtils.DayOfWeek(DT) = 2;
end;

IsSaturday

Checks if the given date is a Saturday.

function IsSaturday(const DT: TDateTime): Boolean;
begin
  Result := SysUtils.DayOfWeek(DT) = 7;
end;

IsSunday

Checks if the given date is a Sunday.

function IsSunday(const DT: TDateTime): Boolean;
begin
  Result := SysUtils.DayOfWeek(DT) = 1;
end;

IsThursday

Checks if the given date is a Thursday.

function IsThursday(const DT: TDateTime): Boolean;
begin
  Result := SysUtils.DayOfWeek(DT) = 5;
end;

IsTuesday

Checks if the given date is a Tuesday.

function IsTuesday(const DT: TDateTime): Boolean;
begin
  Result := SysUtils.DayOfWeek(DT) = 3;
end;

IsWednesday

Checks if the given date is a Wednesday.

function IsWednesday(const DT: TDateTime): Boolean;
begin
  Result := SysUtils.DayOfWeek(DT) = 4;
end;

IsWeekday

Checks if the given date is a weekday.

function IsWeekday(const DT: TDateTime): Boolean;
begin
  Result := SysUtils.DayOfWeek(DT) in [2..6];
end;

IsWeekend

Checks if the given date is a weekend.

function IsWeekend(const DT: TDateTime): Boolean;
begin
  Result := SysUtils.DayOfWeek(DT) in [1, 7];
end;

View the whole database.

Go to the DelphiDabbler website.