Examples Delphi

How many days since start of year
function DayOfYear(ADate: TDateTime): Integer;
var
FirstDate: TDateTime;
YYYY, MM, DD: Word;
begin
DecodeDate(ADate, YYYY, MM, DD);
FirstDate := EncodeDate(YYYY, 1, 1);
Result := Trunc(ADate - FirstDate) + 1;
end;