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.
to S.F.(萧寒(Chinasf)): 不用那么麻烦吧,直接打开Delphi的帮助,输入要看的函数名,打开相应的帮助,如果需要引用什么单元,它的“Unit”中会有说明
TryStrToDateTime 或者TryStrToDate
var dt1: TDateTime; ShowMessage(BoolToStr(TryStrToDate('2003-02-29', dt1), True));
var d: Tdatetime; begin if not TryStrToDateTime('2003-1-35', d) then showmessage('输入的日期字符串是不合法的') else //转换成功,直接使用d
function TryStrToDate(const S: string; out Value: TDateTime): Boolean; 或者 function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;如果合法的日期时间类型的话,返回值为True,并且将转换成日期时间类型的数据赋值到Value中
DateUtils;
的到的结果是10天,请教一下这是怎么回师
要不楼主改为:
inttostr(trunc(now)- trunc(2004-6-4))
或者
inttostr(trunc(now)- trunc(strtodate('2004-6-4')))
还有,就是第二点的情况可以考虑写为:
inttostr(DaysBetween(Date,strtodate('2004-6-4')))
就是说跟Date比较和跟Now比较的结果是不一样的
或者TryStrToDate
dt1: TDateTime; ShowMessage(BoolToStr(TryStrToDate('2003-02-29', dt1), True));
d: Tdatetime;
begin
if not TryStrToDateTime('2003-1-35', d) then
showmessage('输入的日期字符串是不合法的')
else
//转换成功,直接使用d
或者
function TryStrToDateTime(const S: string; out Value: TDateTime): Boolean;如果合法的日期时间类型的话,返回值为True,并且将转换成日期时间类型的数据赋值到Value中