有没有取得两个日期之间天数的函数(100分)

  • 主题发起人 GBlueMan
  • 开始时间
G

GBlueMan

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾,请问有没有取得两个日期之间天数的函数?
形如: function xxx( date1,date2)
返回 date1,date2中相距的天数
如果没有,介绍一种可行的算法也行吧.
 
Trunc(Date1 - Date2)
 
date1-date2就可以
 
delphi 6
function DaysBetween(const ANow, Athen
: TDateTime): Integer;
Description
Call DaysBetween to obtain the difference, in days, between two TDateTime values.
DaysBetween counts only whole days that have elapsed. Thus, DaysBetween reports the difference between Dec 31, 1999 11:59 PM and Jan 1, 2000 11:58 PM as 0 because the difference is one minute short of an entire day.
 
DateTimeToTimeStamp
 
两个日期相减就可以!
 
Trunc(Date1 - Date2)是标准的方法,得出天数,我一向都用它.
若你要得出相关的年,月,日,甚至秒等,还有一个函数,DecodeTime,下面是例子.
procedure TForm1.Button1Click(Sender: TObject);
var
Present: TDateTime;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
begin
Present:= Now;
DecodeDate(Present, Year, Month, Day);
Label1.Caption := 'Today is Day ' + IntToStr(Day) + ' of Month '
+ IntToStr(Month) + ' of Year ' + IntToStr(Year);
DecodeTime(Present, Hour, Min, Sec, MSec);
Label2.Caption := 'The time is Minute ' + IntToStr(Min) + ' of Hour '
+ IntToStr(Hour);
end;
 
同意 Trunc(Date1 - Date2)
 
http://www.delphibbs.com/delphibbs/dispq.asp?lid=731730
http://www.delphibbs.com/delphibbs/dispq.asp?lid=619799
 
两个日期相减就可以!
 
日期型是个浮点数,整数部分是日期的值,单位是(天),小数部分是时间
 
感谢,感谢,我用trunc(date1-date2)搞定了.
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
949
SUNSTONE的Delphi笔记
S
S
回复
0
查看
770
SUNSTONE的Delphi笔记
S
顶部