日期选项

// 根据cxCombox框选择,输出开始时间,结束时间
procedure GetCurSetDate(AcxCombobox: TcxCombobox; var AFromDate, AToDate: TcxDateEdit);
var
iYear, iMonth, iDay: Word;
iWeek: Integer;
CurDate, Dt: TDateTime;
begin
CurDate := StrToDateTime(Now10);
if AcxCombobox.ItemIndex = 0 then //今天
begin
AFromDate.Date := CurDate;
AToDate.Date := CurDate;
end
else if AcxCombobox.ItemIndex = 1 then //昨天
begin
AFromDate.Date := IncDay(CurDate, -1);
AToDate.Date := IncDay(CurDate, -1);
end
else if AcxCombobox.ItemIndex = 2 then //本周
begin
iWeek := DayOfWeek(CurDate) - 1;
AFromDate.Date := CurDate - iWeek + 1;
AToDate.Date := CurDate + 7 - iWeek;
end
else if AcxCombobox.ItemIndex = 3 then //上一周
begin
iWeek := DayOfWeek(CurDate) - 1;
AFromDate.Date := CurDate - iWeek + 1 - 7;
AToDate.Date := CurDate + 7 - iWeek - 7;
end
else if AcxCombobox.ItemIndex = 4 then //本月
begin
DeCodeDate(CurDate, iYear, iMonth, iDay);
AFromDate.Date := StrToDate(Format('%4d-%2d-01', [iYear, iMonth]));
AToDate.Date := IncMonth(AFromDate.Date, 1) - 1;
end
else if AcxCombobox.ItemIndex = 5 then //上一月
begin
Dt := IncMonth(CurDate, -1);
DeCodeDate(Dt, iYear, iMonth, iDay);
AFromDate.Date := StrToDate(Format('%4d-%2d-01', [iYear, iMonth]));
AToDate.Date := IncMonth(AFromDate.Date, 1) - 1;
end
else if AcxCombobox.ItemIndex = 6 then //本年
begin
DeCodeDate(CurDate, iYear, iMonth, iDay);
AFromDate.Date := StrToDate(Format('%4d-01-01', [iYear]));
AToDate.Date := IncYear(AFromDate.Date, 1) - 1;
end
else if AcxCombobox.ItemIndex = 7 then //去年
begin
Dt := IncYear(CurDate, -1);
DeCodeDate(Dt, iYear, iMonth, iDay);
AFromDate.Date := StrToDate(Format('%4d-01-01', [iYear]));
AToDate.Date := IncYear(AFromDate.Date, 1) - 1;
end
else if AcxCombobox.ItemIndex = 8 then //最近7天
begin
AFromDate.Date := IncDay(CurDate, -7);
AToDate.Date := CurDate;
end
else if AcxCombobox.ItemIndex = 9 then //最近1个月
begin
AFromDate.Date := IncMonth(CurDate, -1);
AToDate.Date := CurDate;
end
else if AcxCombobox.ItemIndex = 10 then //最近2个月
begin
AFromDate.Date := IncMonth(CurDate, -2);
AToDate.Date := CurDate;
end
else if AcxCombobox.ItemIndex = 11 then //最近3个月
begin
AFromDate.Date := IncMonth(CurDate, -3);
AToDate.Date := CurDate;
end;
end;

上一篇:sql时间比较的几种写法


下一篇:mysql 根据身份证查询 年龄 性别