//from DateUtils.pas for Delphi6 { Range spanning functions } { YearSpan and MonthSpan are approximates, not exact but pretty darn close } function YearSpan(const ANow, AThen: TDateTime): Double; function MonthSpan(const ANow, AThen: TDateTime): Double; function WeekSpan(const ANow, AThen: TDateTime): Double; function DaySpan(const ANow, AThen: TDateTime): Double; function HourSpan(const ANow, AThen: TDateTime): Double; function MinuteSpan(const ANow, AThen: TDateTime): Double; function SecondSpan(const ANow, AThen: TDateTime): Double; function MilliSecondSpan(const ANow, AThen: TDateTime): Double;
TDateTime实际上是一个实数, 而且差1就表示差一天!
function youranswer(yourdatetime1,yourdatetime2):integer; begin str1:=formatdatetime('yy-mm-dd',yourdatetime1); str2:=formatdatetime('yy-mm-dd',yourdatetime2); str1:=copy(str1,7,2); str2:=copy(str2,7,2); result:=strtoint(str2)-strtoint(str1); end;
2个DateTime类型的相加减就行了。 所得的结果就是你想要的。
var i:Double; i2:integer; begin i:=DateTimePicker1.Date-DateTimePicker2.date; showmessage(floattostr(i)); i2:=strtoint(floattostr(i));
{ Range spanning functions }
{ YearSpan and MonthSpan are approximates, not exact but pretty darn close }
function YearSpan(const ANow, AThen: TDateTime): Double;
function MonthSpan(const ANow, AThen: TDateTime): Double;
function WeekSpan(const ANow, AThen: TDateTime): Double;
function DaySpan(const ANow, AThen: TDateTime): Double;
function HourSpan(const ANow, AThen: TDateTime): Double;
function MinuteSpan(const ANow, AThen: TDateTime): Double;
function SecondSpan(const ANow, AThen: TDateTime): Double;
function MilliSecondSpan(const ANow, AThen: TDateTime): Double;
而且差1就表示差一天!
begin
str1:=formatdatetime('yy-mm-dd',yourdatetime1);
str2:=formatdatetime('yy-mm-dd',yourdatetime2);
str1:=copy(str1,7,2);
str2:=copy(str2,7,2);
result:=strtoint(str2)-strtoint(str1);
end;
2个DateTime类型的相加减就行了。 所得的结果就是你想要的。
i:Double;
i2:integer;
begin
i:=DateTimePicker1.Date-DateTimePicker2.date;
showmessage(floattostr(i));
i2:=strtoint(floattostr(i));