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

如何用javascript判斷字串中必須包含中英文

如何用javascript判...

字串拆開逐字檢查方式~ 首先將每一個字轉換成 ASCII 碼。 在使用for迴圈去檢查每個字是不是在...

找對方法,開創自己的網路流量

找對方法,開創自己的網路流量...

前些天,Tim傳來了一個消息...http://classt...

行事曆功能導入

行事曆功能導入

cc55 Innstory有行事曆囉! 我試著把Innstory當作是我的筆記本,將生活發生的故事紀...

Recommended reading

Other stories happened at this address

RewriteRule仿靜態連結

RewriteRule仿靜態...

前幾天寫了關於頁面導向位置的定義。https://innst...

該看看書了-Mr. Jamie 網路創業七堂課

該看看書了-Mr. Jami...

我愛看書? 其實也並不是。與其說我愛看書,倒不如說我愛買書,因為喜歡看書櫃上擺滿書的樣子... 只是...

判斷捲軸的位置

判斷捲軸的位置

當捲軸往下移動時,判段目前移動到哪個位置... Javascript部份 $(function(){...

來一盤駱式海鮮義大利麵

來一盤駱式海鮮義大利麵

這天我跟客戶開會,晚了...沒趕得急下廚,所以就由Mandy大展身手... 問她需不需要幫忙做什麼,...

紙娃娃

紙娃娃

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

ありがとう 大橋卓彌

ありがとう 大橋卓彌

我,離家多年...歲了..一直在做著遙不可及的夢,走著未知的路...沒什麼長進。 希望有一天,我也可...

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