如何查询当前时间是否在某个时间段内


select * from table where starttime<=curtime() and endtime>=curtime();

 

开始时间小于结束时间 (时间段在一天内)
开始时间大于结束时间 (时间段跨天<不在同一天>)
select id, case when starttime<=endtime then 1 else 0 end as s1
from table
where  (s1=1)  and  curtime() >= starttime and curtime() <= endtime ;
untion all
select id, case when starttime<=endtime then 1 else 0 end as s1
from table
where  (s1=0)  and  curtime() <= starttime and curtime() >= endtime ;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM