Funcao - numero da semana do ano |
Top Previous Next |
|
function SemanadoAno(Data : TDateTime) : word; var wDia,wMes,wAno : word; begin DecodeDate(Data, wAno, wMes, wDia); Result := Trunc(Data - EncodeDate(wAno,1,1)) div 7 + 1; end;
/// another way
{Calculate a week-of-the-year index (0-51) for a given date. Week 0 is the week containing the first Sunday of the year.}
function WeekNum(const TDT:TDateTime) : Word; var Y,M,D:Word; dtTmp:TDateTime; begin DecodeDate(TDT,Y,M,D); dtTmp:=EnCodeDate(Y,1,1); Result:=(Trunc(TDT-dtTmp)+(DayOfWeek(dtTmp)-1)) DIV 7; if Result=0 then Result:=51 else Result:=Result-1; end; |