如何计算精确的日期差值`呢????如:2006-01-19与2006-03-12差几天呢 如何计算精确的日期差值`呢?????如:2006-01-19与2006-03-12差几天呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 加入单元DATEUNTILS,里面有你需要的函数 var dtBegin,dtEnd:TDateTime;begin dtBegin:=StrToDate('2006-01-19'); dtEnd:=StrToDate('2006-03-12'); iDays:=Trunc(dtBegin)-Trunc(dtEnd); 在d中,日期类型实际存储为double类型,可以把日期直接转成double类型来计算。 var t1,t2 : tdatetime; i : integer; begin i := trunc(double(t1) - double(t2) ); end; vard1,d2:Tdatetime;//数组中0..6分别表示:年、月、日、时、分、秒、毫秒a,b:array [0..6]of word;beginDecodeDate(d1,a[0],a[1],a[2]);DecodeTime(d1,a[3],a[4],a[5],a[6]);DecodeDate(d2,b[0],b[1],b[2]);DecodeTime(d2,b[3],b[4],b[5],b[6]);//...接下来就比较 a,b的数值就行了。end; var MyDate1,mydate2: TDateTime; t:double;begin MyDate1 := EncodeDate(StrToInt(Edit1.Text), StrToInt(Edit2.Text), StrToInt(Edit3.Text)); Label1.Caption := DateToStr(MyDate1); MyDate2 := EncodeDate(StrToInt(Edit4.Text), StrToInt(Edit5.Text), StrToInt(Edit6.Text)); Label2.Caption := DateToStr(MyDate2); t:=mydate2-mydate1; label3.Caption:=floattostr(t);end; 接上//Edit1.Text 表示年,Edit2.Text 表示月,Edit3.Text表示日//Edit4.Text 表示年,Edit5.Text 表示月,Edit6.Text表示日 UnitDateUtilsCategorydatetime routinesDelphi syntax:function DaysBetween(const ANow, AThen: TDateTime): Integer;我就不明白楼上的几个人为何非得那样做呢? Returns the number of days (including fractional days) between two specified TDateTime values.UnitDateUtilsCategorydatetime routinesDelphi syntax:function DaySpan(const ANow, AThen: TDateTime): Double;上面的不能用,还有这个,可以返回小数! 日期型其实就是double(d1-d2)/24/0.041666666 trunc(strtodate(2006-03-12)-strtodate(2006-01-19)); DayOfTheYear功能说明:根据指定日期,获取天数。参考实例:Label1.Caption := IntToStr(DayOfTheYear(Now));假设当前日期为2005年1月2日,那么Label将显示为2。表示是2005年的第2天。 对不起,刚才写错了,应该是这样:trunc(strtodate(2006-03-12))-trunc(strtodate(2006-01-19)); 让我写一个超好用的,哈哈哈var dtBegin,dtEnd:TDateTime; DayCount: Integer;begin dtBegin := StrToDate('2006-01-19'); dtEnd := StrToDate('2006-03-12'); DayCount := 0; while not SameDate(dtBegin, dtEnd) do begin IncDay(dtBegin); Inc(DayCount); end; //return DayCountend; word转换pdf 控件支持中文!! 急需delphi的数据库操作图标(bmp)100分送上,在线等待 fileopen 关于插入的一个问题 这段话有什么毛病? 请教高手 Frame 上的控件(图片,文本等) 怎么打印出来? 怎么作预览? 如何使程序最前方。 资源文件可以加入png吗,delphi能操作png文件吗 一个用InstallSHield制作安装程序的问题。 Delphi图象编程高手请进,高分惠客。 看看这个错误提示 请问如何在dbgrid里边获取选定的行的行号?
dtBegin,dtEnd:TDateTime;
begin dtBegin:=StrToDate('2006-01-19');
dtEnd:=StrToDate('2006-03-12');
iDays:=Trunc(dtBegin)-Trunc(dtEnd);
var
t1,t2 : tdatetime;
i : integer;
begin
i := trunc(double(t1) - double(t2) );
end;
d1,d2:Tdatetime;
//数组中0..6分别表示:年、月、日、时、分、秒、毫秒
a,b:array [0..6]of word;
begin
DecodeDate(d1,a[0],a[1],a[2]);
DecodeTime(d1,a[3],a[4],a[5],a[6]);
DecodeDate(d2,b[0],b[1],b[2]);
DecodeTime(d2,b[3],b[4],b[5],b[6]);
//...接下来就比较 a,b的数值就行了。end;
MyDate1,mydate2: TDateTime;
t:double;
begin MyDate1 := EncodeDate(StrToInt(Edit1.Text), StrToInt(Edit2.Text), StrToInt(Edit3.Text));
Label1.Caption := DateToStr(MyDate1);
MyDate2 := EncodeDate(StrToInt(Edit4.Text), StrToInt(Edit5.Text), StrToInt(Edit6.Text));
Label2.Caption := DateToStr(MyDate2);
t:=mydate2-mydate1;
label3.Caption:=floattostr(t);
end;
//Edit1.Text 表示年,Edit2.Text 表示月,Edit3.Text表示日
//Edit4.Text 表示年,Edit5.Text 表示月,Edit6.Text表示日
上面的不能用,还有这个,可以返回小数!
(d1-d2)/24/0.041666666
功能说明:根据指定日期,获取天数。
参考实例:
Label1.Caption := IntToStr(DayOfTheYear(Now));假设当前日期为2005年1月2日,那么Label将显示为2。表示是2005年的第2天。
trunc(strtodate(2006-03-12))-trunc(strtodate(2006-01-19));
dtBegin,dtEnd:TDateTime;
DayCount: Integer;
begin dtBegin := StrToDate('2006-01-19');
dtEnd := StrToDate('2006-03-12');
DayCount := 0;
while not SameDate(dtBegin, dtEnd) do begin
IncDay(dtBegin);
Inc(DayCount);
end;
//return DayCount
end;