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

在PHP裡面如何做到基本的SQL injection防禦?

在PHP裡面如何做到基本的S...

資訊安全一直是很頭痛的問題....我一直以來也在尋找最好的方式... 但在尋找的過程中...至少也得...

PDO連接Mysql方式

PDO連接Mysql方式

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

Android Studio 2.3 隨機改變背景顏色

Android Studio...

class55 開始學習APP 其實我照著工具書上的方式總是在宣告變數時會產生問題~ 例如工具書上寫...

Recommended reading

Other stories happened at this address

行事曆功能導入

行事曆功能導入

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

地圖故事

地圖故事

map 一切都從第一張畫布開始... Innstory裡原先已有寫故事的功能,接著我把故事裡頭的照片...

Google map 功能導入

Google map 功能導...

blogmap 寫故事還是得有地圖才好厚! 前幾天,sam同我說有一個客戶有Google map的需...

Mysql最怕就是手賤

Mysql最怕就是手賤

今天我手賤了眼盲了@@... 錯把delete當成UPDATE....啃!!今天下午超不順的... ...

現在這個時候最幸福

現在這個時候最幸福

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

一個人的簡單午餐...貓飯加上洛葵。

一個人的簡單午餐...貓飯加...

Mandy今天中午不在家。 但她煮了一鍋ABC湯....也煮好了飯。 剛剛下樓炒了一盤時蔬(洛葵),...

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