showmessage(floattostr(now-strtodatetime('2000-10-10')));

解决方案 »

  1.   

    TDateTime其实就是Double
    他的整数部分代表距离1899年12月30日0点的天数(整数个24小时数目),
    小数部分代表除去整数个24小时以后的小时数占24小时的比例。
     例如
      0  代表 1899年12月30日零点
      0。25 代表 1899年12月30日六点
      2。75 代表 1900年1月1日下午六点(18点 )
      -1.25 代表1899年12月29日下午六点(18点)
      注意负数时,代表的时间是: 1899年12月30日零点--整数部分*24小时+小数部分*24小时
    所以计算两个时间变量的差时应该分别讨论:
     两变量都是整数时:直接相减,再取绝对值就可以了.
     一个正一个负时: 正的-负的+2*负的小数部分 .例如,2.25与-1.25的差是:2.25-(-1.25)+(-0.25)*2
     两变量都为负值时:整数部分小数部分分别相减(注意分别相减时的顺序),再相加,再取绝对值.例如-3.25与-1.75的差是:abs(-3-(-1)+(-0.25-(-0.75)))这样就得到了两个日期的差值: 整数部分 个天又小数部分*24 个小时.以下是Delphi帮助文件的原文,其中有个错误, 0 对应的因该是 12/30/1899 0:00 pmTDateTime is a used by the date and time routines to hold date and time values.UnitSystemtype TDateTime = type Double;DescriptionMost VCL objects represent date and time values using the TDateTime type. 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. Following are some examples of TDateTime values and their corresponding dates and times:0 12/30/1899 12:00 am
    2.75 1/1/1900 6:00 pm
    -1.25 12/29/1899 6:00 am
    35065 1/1/1996 12:00 am
    To find the fractional number of days between two dates, simply subtract the two values, unless one of the TDateTime values is negative. Similarly, to increment a date and time value by a certain fractional number of days, add the fractional number to the date and time value if the TDateTime value is positive. 
    When working with negative TDateTime values, computations must handle time portion separately. The fractional part reflects the fraction of a 24-hour day without regard to the sign of the TDateTime value. For example, 6:00 am on 12/29/1899 is –1.25, not –1 + 0.25, which would be –0.75. There are no TDateTime values between –1 and 0.Note: Delphi 1.0 calculated the date from year 1 instead of from 1899. To convert a Delphi 1.0 date to a TDateTime value in later versions of Delphi or in Kylix, subtract 693594.0 from the Delphi 1.0 date. The date format changed to be more compatible with OLE 2.0 Automation.