Loading...

Mysql 查詢時間區間是否包含特定日期

Temperature: 0 °C

ChungChung
author_tools

這其實只是一個簡單的問題,以前並不常用...

但這陣子寫的案子比較偏系統面,這樣的查詢問題變多了@@

問題是這樣的,有一個資料表內容結構如下:


+----+--------+------------+------------+
| id | subject| start_date | end_date |
+----+--------+------------+------------+
| 10 | 標題1 | 2015-01-05 | 2015-04-16 |
| 12 | 標題2 | 2015-04-17 | 2015-04-19 |
| 13 | 標題3 | 2015-04-20 | 2015-07-15 |
| 20 | 標題4 | 2015-07-11 | 2015-08-23 |
| 21 | 標題5 | 2015-08-24 | 2015-12-18 |
+----+--------+------------+------------+

現在有一個日期是2015-07-12,若想查詢上面資料表中開始日期與結束日期間有包含2015-07-12的是哪些資料?

可使用方式:

SELECT * FROM `table` WHERE '2015-07-12' BETWEEN start_date AND end_date;

所以將會得到以下結果

+----+--------+------------+------------+
| id | subject| start_date | end_date |
+----+--------+------------+------------+
| 13 | 標題3 | 2015-04-20 | 2015-07-15 |
| 20 | 標題4 | 2015-07-11 | 2015-08-23 |
+----+--------+------------+------------+

台北市松山區八德路四段650號 Go

https://innstory.com/story-Mysql_查詢時間區間是否包含特定日期-443
寫程式筆記

Prev
 我最愛的檳城美食之一浮羅池滑菜市場的【樂樂Lok_Lok】

Next
來點越南口味武鼎越豐越南麵食館 

Nearby Attractions

台北市松山區八德路四段650號-Nearby Attractions

  • 國立臺灣大學日式宿舍-福州街... Go
  • 台北霞海城隍廟 Go
  • 總統府 Go
  • 原臺北北警察署 Go
  • 殷海光故居 Go
  • 蔡瑞月舞蹈研究社 Go

About the Author

Chung

我是chung
網路工作者
主業是網站系統開發建置
副業是做夢,寫故事
作品請參考/teme.biz
做夢請參考/innstory.com
聯絡/chung.teme@gmail.com

#有人用筆寫日記,有人用歲月寫日記,有人用照片寫日記,而我,用innstory寫日記。

Visitor message

Leave some footprints to prove that you visited me

Recommended reading

Author's other related stories

PDO連接Mysql方式

PDO連接Mysql方式

pexelsphoto 最近因為源碼檢測的原因,才驚覺自己以前的系統撰寫的方式早已不再安全。 所以決...

用distinct在MySQL中查詢多條不重複記錄值

用distinct在MySQ...

select *, count(distinct name) from table group by...

JavaScript的獲取日期代碼不足兩位數補0

JavaScript的獲取日...

當我們用javascript得到了一個時間後...針對月份及日期的部分只會顯示數字... funct...

Recommended reading

Other stories happened at this address

圖文穿插效果

圖文穿插效果

寫故事還是得圖文穿插看起來方便些~ 其實一直都在找最適合寫故事的方式,一開始我把所有上傳照片都放在故...

紙娃娃

紙娃娃

flower 紙娃娃其實是我給這個專案的名稱.... 因為做這功能時讓我想起來小時候看鄰居家小女孩玩...

現在這個時候最幸福

現在這個時候最幸福

幸福是什麼? 中樂透頭獎時.....或是功成名就時? 我很少過自己的生日....在家裡..因為跟家姊...

鍾姓三嘗祠堂

鍾姓三嘗祠堂

chung 接下這個專案時....其實心裡有些感觸...... 隨著年齡越來越大....對於血緣的部...

用distinct在MySQL中查詢多條不重複記錄值

用distinct在MySQ...

select *, count(distinct name) from table group by...

你是不是像我就算受了冷漠,也不放棄自己想要的生活。

你是不是像我就算受了冷漠,也...

累了就該充電一下,聽首好歌... 好歌總能激勵人心。 不寫,就會就永遠寫不完......寫了,遲早有...

Please select an option

error

Hi, thank you for your participation, but you cannot vote repeatedly~

Join innstory now and start recording your story.

"Innstory" is a place to store stories. We are committed to becoming a warm platform. Deepening the bonds between people is our direction.
We are convinced that the blockchain between people is not just a cold calculation. Join us now.

Wrong format