两个字段DATE1,DATE2查找出相应的记录,把DATE1-DATE2=COLUMN13但是要求结果为  :    17:00-09:30 计算出结果为8 
                      17:00-09:00 计算出结果为8 
                      17:30-09:00 计算出结果为9 
程序代码应该怎么写?我的做法
query1.fieldvalues['column'];:=inttostr(round(strtotime(query1.fieldvalues['date1'])-strtotime(query1.fieldvalues['date2']))*24) 怎么每次结果都是0,我都晕了!谢谢各位指教!

解决方案 »

  1.   

    我以前写过一个计算时间的函数,Function shijian( s:string ):real;  //s为读取的时间转化为string
    var i,j:integer;
        a,b:integer;
    begin
    a:=0;
    b:=0;for i:=1 to length(s) do
    begin
    if s[i]<>':' then
    a:=a*10+strtoint(s[i])
    else
    break;
    end;for j:=1 to length(s) do
    begin
    if  s[j]=':' then
    b:=strtoint(s[j+2])+strtoint(s[j+1])*10;
    end;shijian:=b+a*60;                         //返回分钟数
    end;
      

  2.   


    SetRoundMode(rmNearest);  //设定round函数舍入规则
    query1.fieldvalues['column'];=inttostr(round((strtotime(query1.fieldvalues['date1'])-strtotime(query1.fieldvalues['date2']))*24)) //应该在round函数后加一对括号
      

  3.   

    系统提示出错!说
    '2004-9-1 18:00:00' is not a valid integer value
    试了几个明天都不能转为INT,应该怎么做才好
      

  4.   

    终于试出来了,谢谢大家query1.FieldValues['gs']:=round((strtodatetime(query1.FieldValues['zhi'])-strtodatetime(query1.FieldValues['qi']))*24);应该是函数用错!
    这样的情况应该用STRTODATETIME,不能用STRTOTIME!我在ORACLE测试时是用ROUND(STRTOTIME('18:00','HH:MI')-STRTOTIME('09:30'),'HH:MI')测试通过的,所以以为用STRTOTIME是可以的,可能在DELPHI里面不行
      

  5.   

    strtotime 使用HH:MM:SS 格式,包含日期要用StrtoDateTime函数
      

  6.   

    是以前,我在STRTOTIME加HH:MM:SS,系统提示我参数太多,不知道怎么回事