如何获取两个日期之间相隔的天数?

dgdlking 2003-09-17 03:47:24
有没有这样的函数?或者什么其他比较简单的方法?
...全文
123 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangguan007 2003-09-17
  • 打赏
  • 举报
回复
Unit
DateUtils

function DaysBetween(const ANow, AThen: TDateTime): Integer;

Call DaysBetween to obtain the difference, in days, between two TDateTime values.
Hyacinthus 2003-09-17
  • 打赏
  • 举报
回复
呵呵,,够简单实用吧,~~~给分吧!!!~~
Hyacinthus 2003-09-17
  • 打赏
  • 举报
回复
简单~ 一个sql语句搞定:
例如:
select to_date ('2002-6-26','yyyy-mm-dd')-to_date('2000-03-14','yyyy-mm-dd') days from dual
hongqi162 2003-09-17
  • 打赏
  • 举报
回复
unit Unit2;

interface

uses

DateUtils;
procedure TForm2.Button1Click(Sender: TObject);
var
n:integer;
begin

n:=daysbetween(DateTimePicker1.DateTime,DateTimePicker2.DateTime);
edit1.Text:=inttostr(n);
end;
FrameSniper 2003-09-17
  • 打赏
  • 举报
回复
DaysBetween
DaySpan
yzykjh 2003-09-17
  • 打赏
  • 举报
回复
function DaySpan(const ANow,AThen: TDateTime): Double; //相差的天数
lzybfs 2003-09-17
  • 打赏
  • 举报
回复
两个日期相减就可以了
superTY 2003-09-17
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/2270/2270028.xml?temp=.0192377

上面刚讨论过,看看吧。
hongqi162 2003-09-17
  • 打赏
  • 举报
回复
var
n1,n2:string;
n:integer;
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= DateTimePicker1.DateTime ;
DecodeDate(Present, Year, Month, Day);
n1:=inttostr(day);
Present:= DateTimePicker2.DateTime ;
DecodeDate(Present, Year, Month, Day);
n2:=inttostr(day);
n:=Trunc(strtoint(n2) - strtoint(n1));
edit1.Text:=inttostr(n);
end;
laohai 2003-09-17
  • 打赏
  • 举报
回复

daysbetweem()函数
我的一段代码,应该有用
days:=DaysBetween(strtodate(form6.MaskEdit1.text),strtodate(form6.MaskEdit2.text));

form18.StaticText18.Caption:=inttostr(days);
shmilyjiujiu 2003-09-17
  • 打赏
  • 举报
回复

var
tWork1,tOp1:Ttime;
tWork2 : string;
begin
tWork1:=now;
sleep(1000000);
tOp1:=now;
tWork2:=TimeToStr(tWork1-tOp1);
showmessage(tWork2)
end;
换成日期即可

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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