我想用sql判断我现在的时间 在不在某个时间段 怎么来实现 请各位大侠指点 谢谢!

解决方案 »

  1.   

    access  
    select * from xxx where xxx between #2001-01-01# and #2012-01-01#sqlserver
    select * from xxx where xxx between '2001-01-01' and '2012-01-01'
      

  2.   

    datetime类型的可以直接比较,string类型则需要转换后比较
      如,判断YourTime在不在 “时间1”和“时间2”之间getdate()>=时间1   and    getdate()<=时间2
      

  3.   

    select * from A where GETDATE() not between '2012-02-01' and '2012-08-03'
      

  4.   

    select * from tablename where
    datediff(d,时间字段,getdate())=0 and
    datepart(h,时间字段)>=9  and datepart(h,时间字段)<=12
      

  5.   

     not between ……and ……
      

  6.   

    例如我要判断目前时间是不是在9:20分到12:00之间  每天这个时间段为交易时段,这个用sql语句有办法实现没?
      

  7.   

    例如我的交易时间是每天的9:20分到下午6:00  用sql语句怎么来判断目前的时间是否是在交易时段?
      

  8.   


    strtime>='2012-07-11 9:17:20' and strtime<='2012-07-11 18:17:20'带上时分秒
      

  9.   

    select dateName(hh,getdate()) +':'+  dateName(Mi,getdate()) +':'+  dateName(Second,getdate())       --获取系统当前时间 如15:12:38比较的话...等待高人出现
      

  10.   

    SELECT CONVERT(DATETIME,CONVERT(varchar,GETDATE(),101)+' 09:00:000')
    --2012-07-18 09:00:00.000
      

  11.   

    ---检测当前时间是否为早上0:00:00.000 到 07:30:00.000 之间DECLARE @Seconds int;
    DECLARE @CurrentDate DATETIME;
    DECLARE @LimitDate DATETIME;
    SELECT @CurrentDate = GETDATE();
    SELECT @LimitDate = CONVERT(DATETIME, 
    CONVERT(VARCHAR(10), GETDATE(), 21) + ' 07:30:00')
    SELECT @Seconds = DATEDIFF(second, @CurrentDate, @LimitDate)
    IF(@Seconds > 0)
    BEGIN
    SELECT @CurrentDate = @CurrentDate - 1;
    ENDSELECT CONVERT(DATETIME, CONVERT(VARCHAR(10), 
    @CurrentDate, 21) + ' 00:00:00');