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

使FCKeditor所上傳的圖檔檔名亂數化

使FCKeditor所上傳的...

編輯"../fckor/or/filemanager/connectors/php/com...

瀏覽器升級ie9後FCKEditor無法使用對話框解決方法

瀏覽器升級ie9後FCKEd...

原文網址:http://ecshop.tw/bbs/archiver/tid.html 升級到 IE...

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

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

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

Recommended reading

Other stories happened at this address

RewriteRule仿靜態連結

RewriteRule仿靜態...

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

圖型插件Elastislide

圖型插件Elastislid...

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

意外的客人

意外的客人

今晚,我的水族箱裡來了一位嬌客,【豆娘】... s 我想,牠應該是前幾天去水族店買黑殼蝦時偷渡來的....

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

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

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

馬來西亞-薩騎馬?

馬來西亞-薩騎馬?

想事情的時候,喜歡在嘴裡咬東西...餅乾、糖果。 但最近家裡缺糧...沒有補貨。剛好想到前些日子布萊...

Google map 功能導入

Google map 功能導...

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

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