zoukankan      html  css  js  c++  java
  • 处理不包含日期的时间段

    数据库表有begintime endtime两个时间类型字段,取现在任一时间,查询数据库记录问题??
    数据库表T_time
    mark begintime endtime
    0     8:00:00   16:00:00
    1     16:00:00   0:00:00
    2     0:00:00    8:00:00

    比如我现在已知电脑时间为 9:00:00如何查出第一条记录?比如已知时间为17:00:00,如何查出第二条记录??
    select * from t_time where begintime <= '9:00:00 ' and endtime > '9:00:00 '
    或 select * from t_time  '9:00:00 ' between begintime and endtime 都不可以呀,怎么整??

    ----

    declare @T_time table(mark int,begintime datetime,endtime datetime)
    insert @T_time
    select 0,'8:00:00','16:00:00' union all
    select 1,'16:00:00','0:00:00' union all
    select 2,'0:00:00','8:00:00'

    select begintime,
        endtime
    =case when datediff(day,begintime,endtime)>=1
            
    then dateadd(d,-1,endtime)
            
    else endtime
        
    end
    from 
    (    
    select 
            begintime, 
            endtime
    =case when endtime<begintime 
            
    then dateadd(d,1,endtime)
            
    else endtime
        
    end 
        
    from @T_time ) b 
    where '18:0:0' between b.begintime and b.endtime

    --假设begintime,endtime为字符型 
    select * from tb where convert(varchar(8),getdate(),114)  >= begintime and convert(varchar(8),getdate(),114)  <= endtime

  • 相关阅读:
    一个简单粗暴的爬虫
    Linux 目录结构
    python 部署 Restful web
    JVM 运行时数据区总结 栈 堆 堆大小配置总结
    成都法律援助申请流程
    JavaEE error整理(不断更新)
    ehcache.xml 属性大全
    SpringMVC 构建Restful风格 及问题处理
    Http Content-Type
    Redis 教程 Java工程师学习知识点
  • 原文地址:https://www.cnblogs.com/feixian49/p/917170.html
Copyright © 2011-2022 走看看