如何查詢當前時間是否在某個時間段內


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