为什么这两组日期的月份间隔都是1
为何这两组日期的月份间隔都是1?
t1:=StrToDate('2012-02-01');
t2:=StrToDate('2012-04-01');
showmessage(inttostr(monthsbetween(t2,t1)));
t1:=StrToDate('2012-03-01');
t2:=StrToDate('2012-04-01');
showmessage(inttostr(monthsbetween(t2,t1)));
为何结果都是1?
------解决思路----------------------
function MonthsBetween(const ANow, AThen: TDateTime): Integer;
描述:根据两个给定的TDateTime类型的参数ANow和AThen,MonthsBetween函数能得到两个日期在月份上差距数。
因为月份的天数是不同的,所以 MonthsBetween 函数返回的是一个近似值,该近似值基于每个月份为 30.4375 天。不足一个月的数字将不被计算。因此,例如,对于 2月1日 到 2月28日,MonthsBetween 返回的数值为 0。同样,对于 2月1日 到 3月1日,MonthsBetween 返回的数值也是 0。
SO,我的理解是因为二月天数不足30天
t1:=StrToDate('2012-02-01');
t2:=StrToDate('2012-04-01');
showmessage(inttostr(monthsbetween(t2,t1)));
t1:=StrToDate('2012-03-01');
t2:=StrToDate('2012-04-01');
showmessage(inttostr(monthsbetween(t2,t1)));
为何结果都是1?
------解决思路----------------------
function MonthsBetween(const ANow, AThen: TDateTime): Integer;
描述:根据两个给定的TDateTime类型的参数ANow和AThen,MonthsBetween函数能得到两个日期在月份上差距数。
因为月份的天数是不同的,所以 MonthsBetween 函数返回的是一个近似值,该近似值基于每个月份为 30.4375 天。不足一个月的数字将不被计算。因此,例如,对于 2月1日 到 2月28日,MonthsBetween 返回的数值为 0。同样,对于 2月1日 到 3月1日,MonthsBetween 返回的数值也是 0。
SO,我的理解是因为二月天数不足30天