大家好:
我申请了两个TDate 类型的变量 D1、D2 ,分别赋值为:D1 := StrtoDate('2004-12-1'); D2 := now 。我想得到D2-D1 之间的天数请问我应该怎么做?????????????????????????????????????????????????????????????????????然后把得到的天数再乘以整数100。!!!!!!!!!!!!!!!请问我应该怎么做啊 ????????????????
我申请了两个TDate 类型的变量 D1、D2 ,分别赋值为:D1 := StrtoDate('2004-12-1'); D2 := now 。我想得到D2-D1 之间的天数请问我应该怎么做?????????????????????????????????????????????????????????????????????然后把得到的天数再乘以整数100。!!!!!!!!!!!!!!!请问我应该怎么做啊 ????????????????
days := Frac(D2-D1);
或 days := Round(D2-D1);
days 如果是整数可以
days := Trunc(D2-D1); 直接取整
或 days := Round(D2-D1); 四舍五入
2.75 1/1/1900 6:00 pm
-1.25 12/29/1899 6:00 am
35065 1/1/1996 12:00 am
To find the fractional number of days between two dates, simply subtract the two values, unless one of the TDateTime values is negative. Similarly, to increment a date and time value by a certain fractional number of days, add the fractional number to the date and time value if the TDateTime value is positive.
When working with negative TDateTime values, computations must handle time portion separately. The fractional part reflects the fraction of a 24-hour day without regard to the sign of the TDateTime value. For example, 6:00 am on 12/29/1899 is ?.25, not ? + 0.25, which would be ?.75. There are no TDateTime values between ? and 0.Note: Delphi 1.0 calculated the date from year 1 instead of from 1899. To convert a Delphi 1.0 date to a TDateTime value in later versions of the Delphi language, subtract 693594.0 from the Delphi 1.0 date.
定义:D2_Year,D2_Month,D2_Day,D1_Year,D1_Month,D1_Day:Word;
DecodeDate(D1,D1_Year,D1_Month,D1_Day);
DecodeDate(D2,D2_Year,D2_Month,D2_Day);
D2-D1 之间的天数:=D1_Day-D2_Day
就是两个日期之间相隔的天数;