Delphi根据输入日期按年月周日输出日期段


Delphi根据输入日期按年月周日输出日期段

输入变量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
:begin //日

ADateStart := ADate;

ADateEnd := ADate + 1;

end;
:begin //周 DayOfWeek() Sunday =1

if DayOfWeek(ADate)<>2 then // <> Monday

ADateStart := ADate - DayOfWeek(ADate) + 2

else

ADateStart := ADate;

ADateEnd := ADateStart + 6; //周日

end;
:begin //月 xx-xx-01 to xx-yy-01

DecodeDate(ADate, myYear, myMonth, myDay);

ADateStart := StrtoDate(inttostr(myYear) + '-' + inttostr(myMonth) + '-01');

ADateEnd := incmonth(ADateStart);

end;
: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;


联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678