E Ekin Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-29 #1 如何得到一个日期两年以后的日期(select dateadd(year,2,getdate())),但是好像在碰到闰年后就不好使了!用decodedate拆分后年加2也再encodedate,如何解决2月的28.29天的问题。
如何得到一个日期两年以后的日期(select dateadd(year,2,getdate())),但是好像在碰到闰年后就不好使了!用decodedate拆分后年加2也再encodedate,如何解决2月的28.29天的问题。
M muhx Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-29 #2 记得加入DateUtils单元 function IncYear(const AValue: TDateTime; const ANumberOfYears: Integer = 1): TDateTime; Description IncYear returns the value of the AValue parameter, incremented by ANumberOfYears years. ANumberOfYears can be negative, to return a date N years previous. The time of day specified by the AValue parameter is copied to the result.
记得加入DateUtils单元 function IncYear(const AValue: TDateTime; const ANumberOfYears: Integer = 1): TDateTime; Description IncYear returns the value of the AValue parameter, incremented by ANumberOfYears years. ANumberOfYears can be negative, to return a date N years previous. The time of day specified by the AValue parameter is copied to the result.
M muhx Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-29 #4 例子给你,分给我 procedure TForm1.Button1Click(Sender: TObject); var tmpDate: TDate; begin tmpDate := EncodeDate(2008, 2, 29); IncYear(tmpDate, 2); ShowMessage(DateToStr(IncYear(tmpDate, 2))); end;
例子给你,分给我 procedure TForm1.Button1Click(Sender: TObject); var tmpDate: TDate; begin tmpDate := EncodeDate(2008, 2, 29); IncYear(tmpDate, 2); ShowMessage(DateToStr(IncYear(tmpDate, 2))); end;
E Ekin Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-29 #5 to:网中戏 这样要是碰见366天的这么办? to:muhx 分不是问题,可以再加。 你的做法和我问题中说的第二种方法没有区别!
H hityou Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-29 #6 直接用sql没有什么问题啊,select dateadd(year,2,'2008-02-29')得到的是28号,
M muhx Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-30 #7 我的例子主要给你演示IncYear函数的使用啊 闰年的2月29号经过IncYear后变成非闰年的28号了 应该符合你的要求了 你仔细看看我的方法和你第二个方法的区别 如果EncodeDate(2008 + 2, 2, 29)那么就会报错。 在Delphi的源代码中使用了两个数组常量分别保存闰年和非闰年每个月的天数 你自己写个例子使用IncYear试一下吧
我的例子主要给你演示IncYear函数的使用啊 闰年的2月29号经过IncYear后变成非闰年的28号了 应该符合你的要求了 你仔细看看我的方法和你第二个方法的区别 如果EncodeDate(2008 + 2, 2, 29)那么就会报错。 在Delphi的源代码中使用了两个数组常量分别保存闰年和非闰年每个月的天数 你自己写个例子使用IncYear试一下吧
M muhx Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-30 #8 我已经试过了,闰年的2月29号加4年 比如tmpLeapYear是2008年2月29日那么 IncYear(tmpLeapYear, 4)得到的是2012年的2月29号 应该可以满足你的要求
懒 懒虫007 Unregistered / Unconfirmed GUEST, unregistred user! 2006-05-30 #9 完全同意mubx的用法,IncYear函数应该已经考虑过闰年等大家能想到的影响结果的因素了,具体可以看看代码自己试下