有没有一个日期函数可以返回上个月的日期呢?(50分)

  • 主题发起人 workingdelphi
  • 开始时间
W

workingdelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
比如说现在是 2002-09-01,我现在要根据当前的日期得到上一个月的日期,
有没有函数可以用的呢?谢谢了。
 
function lastmonth(ADate: TDateTime): TDateTime;
var
y, m, d: word;
begin
decodedate(adate, y, m, d);
dec(m);
if m = 0 then
begin
m := 12;
dec(y);
end;
try
result := encodedate(y, m, d);
except
inc(m);
if m>12 then
begin
m := 1;
inc(y);
end;
d := 1;
result := encodedate(y, m, d)-1;
end;
end;
 
To:pearl
谢谢你。
 
顶部