请问在DELPHI中如何取的两个时间段的差值呢?

wellshddelphi 2003-08-25 12:04:11
比如有两个时间段:
datetimepicker1中显示时间 2002/03/05 15:23:34
datetimepicker2中显示时间 2003/03/12 8:20:58
请问有什么办法可以获得这两个时间的时间差呢?
...全文
87 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
xx9yk 2003-08-26
  • 打赏
  • 举报
回复
function DateTimeDiff(dtp1,dtp2:TDateTimePicker):double; //多少天含時間差
begin
result:=dtp1.DateTime-dtp2.DateTime;
end;
function DateDiff(dtp1,dtp2:TDateTimePicker):integer; //多少天
begin
result:=dtp1.DateTime-dtp2.DateTime;
end;

譬如:
datetimepicker1 的值为 2003-8-30 12:00时
datetimepicker2 的值为 2003-8-25 18:00时
DateTimeDiff(datetimepicker1 ,datetimepicker2) 返回4.75
DateDiff(datetimepicker1 ,datetimepicker2) 返回4
就這樣 所以Delphi中沒必要搞個函數了,
還有trunc(dtp1.DateTime,dtp2.DateTime) 返回4
Good luck
xx9yk 2003-08-25
  • 打赏
  • 举报
回复
more clear for
datetimepicker1.DateTime-datatimepicker2.DateTime
xx9yk 2003-08-25
  • 打赏
  • 举报
回复
the unit of result of datetimepicker1.date-datatimepicker2.date will be N.NN.. days.
Good luck!
aiunong 2003-08-25
  • 打赏
  • 举报
回复
gz
wellshddelphi 2003-08-25
  • 打赏
  • 举报
回复
在DELPHI中没有解决该问题的函数吗?
wellshddelphi 2003-08-25
  • 打赏
  • 举报
回复
干脆问一下:在DELPHI解决这种问题
xx9yk 2003-08-25
  • 打赏
  • 举报
回复
see also constance part of SysUtils.pas
-----------------------
{ Units of time }
HoursPerDay = 24;
MinsPerDay = HoursPerDay * 60;
SecsPerDay = MinsPerDay * 60;
MSecsPerDay = SecsPerDay * 1000;

{ Days between 1/1/0001 and 12/31/1899 }
DateDelta = 693594;

{ Days between TDateTime basis (12/31/1899) and Unix time_t basis (1/1/1970) }
UnixDateDelta = 25569;
xx9yk 2003-08-25
  • 打赏
  • 举报
回复
oh! datetimepicker1.DataTime 是TDataTime類.
According to HelpFile, we got....
type TDateTime = type Double;
The integral part of a TDateTime value is the number of days that have passed since 12/30/1899.
The fractional part of a TDateTime value is fraction of a 24 hour day that has elapsed.
Hence, Trunc(datetimepicker1.DateTime-datatimepicker2.DateTime) got 4 or 5 according to the Time Part!
Good Luck!
tongki 2003-08-25
  • 打赏
  • 举报
回复
var
sjc:integer;

sjc:=datetimepicker1.DateTime-datatimepicker2.DateTime;
okgxs 2003-08-25
  • 打赏
  • 举报
回复
今天刚刚多了一个“三角库头”就来帮你了
okgxs 2003-08-25
  • 打赏
  • 举报
回复
关键是!min :=dtr*24*60*60; //多少秒
okgxs 2003-08-25
  • 打赏
  • 举报
回复
dts:=dm.cds_input.FieldByName('呼叫时间').AsDateTime;
dte:=now;
dtr :=dte-dts;
min :=dtr*24*60*60; //秒 (strtoint(waitaccept)/1000))
wellshddelphi 2003-08-25
  • 打赏
  • 举报
回复
楼上的,依你的方法是行不通的,
datetimepicker1.DateTime-datatimepicker2.DateTime
比如:
datetimepicker1 的值为 2003-8-30时
datetimepicker1 的值为 2003-8-25时
返回值显示为:1900-1-3
我也不知道他这个结果是怎么得来的.哎.

2,497

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧