比如:23:02:03,怎么知道是在22:00:00-08:00:00(第二天)
      09:12:03,怎么知道是在08:00:00-22:00:00 之间
请高手指教;
不想通过下面的方式来实现;
  dt1:=StrToTime( '23:02:03 ');
  if (dt1>StrToTime( '08:00:00 '))  and  (dt1<StrToTime( '22:00:00 '))  then
    showmessage('时间在08——22')
  else
  begin
    if (dt1>StrToTime( '22:00:00 '))   or  (dt1<StrToTime( '08:00:00 '))  then
      showmessage('时间在22——08');
  end

解决方案 »

  1.   

    Use DateUntis;
    var 
      Hour : Word;
    begin
      Hour := HourOf(dt1);  //得到小时
      然后
      if (Hour>=8) and (Hour<=23);
      .....
      

  2.   

    补充一下,还要比较分钟和秒的话,MinuteOf,SecondOf,
    或者干脆用DecodeTime
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      dt1,dt2:TDateTime;
    begin
      dt1:=StrToTime('23:02:03');
      dt2:=StrToTime('08:02:03');
      Case InOutTimeJudge(dt1,dt2) of
        1:showmessage('都在第一段');
        2:showmessage('都在第二段');
        3:showmessage('第一段进,第二段出');
        4:showmessage('第二段进,第一段出');
      end;
    end;Function TForm1.InOutTimeJudge(InDateT,OutDateT:TDateTime):Integer;
    var
      sign:Integer;
    begin
      sign:=TimeISJudge(InDateT);
      if TimeISJudge(InDateT)=TimeISJudge(OutDateT) then
      begin
        if sign=1 then Result:=1;   //二个时间都在第一段
        if sign=2 then Result:=2;   //二个时间都在第二段
      end
      else
      begin
        if sign=1 then Result:=3;  //第一段进,第二段出
        if sign=2 then Result:=4;  //第二段进,第一段出
      end;
    end;Function TForm1.TimeISJudge(DateT:TDateTime):Integer;
    begin
      if (DateT>StrToTime( '08:00:00 '))  and  (DateT<StrToTime( '22:00:00 '))  then
        Result:=1
      else
      begin
        if (DateT>StrToTime( '22:00:00 '))   or  (DateT<StrToTime( '08:00:00 '))  then
          Result:=2;
      end
    end;
      

  4.   

    用Delphi的日期函数date()获得系统的日期,Delphi还有几个与日期有关的函数。
      

  5.   

    其实还是用的StrToDateTime的方式
      

  6.   

    参考下这个吧 select CONVERT(varchar(12) , getdate(), 101 )
    09/12/2004 select CONVERT(varchar(12) , getdate(), 103 )
    12/09/2004 select CONVERT(varchar(12) , getdate(), 104 )
    12.09.2004 select CONVERT(varchar(12) , getdate(), 105 )
    12-09-2004 select CONVERT(varchar(12) , getdate(), 106 )
    12 09 2004 select CONVERT(varchar(12) , getdate(), 107 )
    09 12, 2004 select CONVERT(varchar(12) , getdate(), 108 )
    11:06:08

    select CONVERT(varchar(12) , getdate(), 109 )
    09 12 2004 1 select CONVERT(varchar(12) , getdate(), 110 )
    09-12-2004 select CONVERT(varchar(12) , getdate(), 113 )
    12 09 2004 1 select CONVERT(varchar(12) , getdate(), 114 )
    11:06:08.177用这个语句就可取到日期
    select CONVERT(varchar(12) , 你的日期字段, 108 )  as 时间段
    11:06:08  ‘08:00:00’<=时间段>=‘12:59:59’
      

  7.   

    时间  实际上是一个 Double 
    时间字符串转换成 时间类型直接 比较就行了。。
      

  8.   

    晕倒还要搞到SQL中去你太牛了