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

清除網頁暫存(no cache)

清除網頁暫存(no cach...

pexelsphoto5 在製作專案時,有沒有試過JS 或 CSS 明明就已經更新了~ 但頁面卻像鬼...

.sql檔過大無法匯入phpMyAdmin

.sql檔過大無法匯入php...

修改phpMyAdmin資料夾中的config.inc.php檔。 打開後找到下列兩行或自行加入: ...

在手機上如何建立網址到手機桌面中並且使用圖示

在手機上如何建立網址到手機桌...

上回做專案時,客戶說了手機桌面上的網站捷徑太醜,想要美化。 這回索性也幫Innstory美化一下,順...

Recommended reading

Other stories happened at this address

現在這個時候最幸福

現在這個時候最幸福

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

Mandy說我想要募款去紐西蘭@@

Mandy說我想要募款去紐西...

bg (示意圖,不確定是不是南湖大山..是在寫太魯閣系統時使用的素材) 南湖大山位於台灣的中央山脈主...

圖型插件Elastislide

圖型插件Elastislid...

teach Elastislide是一款好用的圖形插件......

Google map 功能導入

Google map 功能導...

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

今晚晚餐,簡單又營養蛤蜊湯。

今晚晚餐,簡單又營養蛤蜊湯。...

假日的晚餐.... s 就這一碗蛤蜊湯... 因為,太晚吃午餐。因為,肚子還太飽。 所以Mandy煮...

地圖故事

地圖故事

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

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