Calculer le numéro de la semaine

var
FirstWeekDay : Integer = 2;

function WeekToDate(AWeek,AYear:Integer):TDateTime;
begin
Result:=EncodeDate(AYear,1,FirstWeekDate);
Result:=Result+(AWeek-1)*7-((DayOfWeek(Result)+(7-FirstWeekDay)) mod 7);
end;

procedure DateToWeek(ADate:TDateTime; var AWeek,AYear:Word);
var
Month,Day : Word;

begin
ADate:=ADate-((DayOfWeek(ADate)-FirstWeekDay+7) mod 7)+ 7-FirstWeekDate;
DecodeDate(ADate,AYear,Month,Day);
AWeek:=(Trunc(ADate-EncodeDate(AYear,1,1)) div 7)+1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(FormatDateTime('dd.mm.yyyy',WeekToDate(51,2000)));
end;

procedure TForm1.Button2Click(Sender: TObject);
var
week,year:Word;

begin
DateToWeek(now,week,year);
ShowMessage(inttostr(week));
ShowMessage(inttostr(year));
end;
Ajouter un commentaire
Pseudo
Adresse email
Site internet (optionnel)
Votre commentaire
Fiche de l'article
Mise a jour29/11/2001
VisualisationVu 1505 fois
PublicInternaute zz
CategorieDelphi - Trucs et astuces - Autre categorie
Auteur de l'article
SwissDelphiCenter SwissDelphiCenter
connecté le 02/11/2011
329 articles dans la section
Contacter l'auteur