输入变量ADateStart,并为其填写起始日期,变量ADateEnd,计算类型AType,
输出变量ADateStart,变量ADateEnd
procedure FormatDateByType(AType:Integer; var ADateStart, ADateEnd: TDate);
var //type 0日 1周 2月 3年
ADate :TDate;
myYear, myMonth, myDay : Word;
begin
ADate := ADateStart;
case AType of
0:begin //日
ADateStart := ADate;
ADateEnd := ADate + 1;
end;
1:begin //周 DayOfWeek() Sunday =1
if DayOfWeek(ADate)<>2 then // <> Monday
ADateStart := ADate - DayOfWeek(ADate) + 2
else
ADateStart := ADate;
ADateEnd := ADateStart + 6; //周日
end;
2:begin //月 xx-xx-01 to xx-yy-01
DecodeDate(ADate, myYear, myMonth, myDay);
ADateStart := StrtoDate(inttostr(myYear) + '-' + inttostr(myMonth) + '-01');
ADateEnd := incmonth(ADateStart);
end;
3:begin //年 xx-01-01 to yy-01-01
DecodeDate(ADate, myYear, myMonth, myDay);
ADateStart := StrtoDate(inttostr(myYear)+'-01-01');
ADateEnd := StrtoDate(inttostr(myYear+1)+'-01-01');
end;
end;
end;
var //type 0日 1周 2月 3年
ADate :TDate;
myYear, myMonth, myDay : Word;
begin
ADate := ADateStart;
case AType of
0:begin //日
ADateStart := ADate;
ADateEnd := ADate + 1;
end;
1:begin //周 DayOfWeek() Sunday =1
if DayOfWeek(ADate)<>2 then // <> Monday
ADateStart := ADate - DayOfWeek(ADate) + 2
else
ADateStart := ADate;
ADateEnd := ADateStart + 6; //周日
end;
2:begin //月 xx-xx-01 to xx-yy-01
DecodeDate(ADate, myYear, myMonth, myDay);
ADateStart := StrtoDate(inttostr(myYear) + '-' + inttostr(myMonth) + '-01');
ADateEnd := incmonth(ADateStart);
end;
3:begin //年 xx-01-01 to yy-01-01
DecodeDate(ADate, myYear, myMonth, myDay);
ADateStart := StrtoDate(inttostr(myYear)+'-01-01');
ADateEnd := StrtoDate(inttostr(myYear+1)+'-01-01');
end;
end;
end;