WeeksInYear returns the number of weeks in the year of the specified TDateTime value specified by AValue.

WeeksInYear defines the first week of the year according to the ISO 8601 standard, so the first week of the year is the one that includes the first Thursday of the year (the first week that has four or more days in the year). This means that WeeksInYear always returns either 52 or 53.

Declaration: Function WeeksInYear(const AValue: TDateTime): Word;

An example follows.

procedure ScriptEvent(var Value:Variant);
var
NumWeeks : word;
begin
NumWeeks := WeeksInYear(Date);
LogInfo('Number of weeks - '+IntToStr(NumWeeks));
 
NumWeeks := WeeksInYear(IncYear(Date,1));
LogInfo('Number of weeks - '+IntToStr(NumWeeks));
 
LogInfo('');
LogInfo('');
end;