Re: [SQL ] 比較日期
※ 引述《dream1129 ( 人各有志)》之銘言:
: 就是我要抓出一段時間內的資料,
: 比如2006/09/01~2006/09/05
: 要怎麼下query呢?
: select * from table where date>=2006/09/01 and date<=2006/09/05
如果能換成timestamp就很好弄了@@
各家的系統提供不太相同的date function
btw. 這裡有一些mysql的範例
==============================================================
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
Posted by Luke Burgess on February 21 2005 6:11pm [Delete] [Edit]
There doesn't appear to be an official way of selecting * from a table where
eg 'date is january 2005'. So far i've found 8 different ways!!
1. where date like '2005-01-%'
2. where DATE_FORMAT(date,'%Y-%m')='2005-01'
3. where EXTRACT(YEAR_MONTH FROM date)='200501'
4. where YEAR(date)='2005' and MONTH(date)='1'
5. where substring(date,1,7)='2005-01'
6. where date between '2005-01-01' and '2005-01-31'
7. where date >= '2005-01-01' and date <= '2005-01-31'
8. where date
IN('2005-01-01','2005-01-02','2005-01-03','2005-01-04',
'2005-01-05','2005-01-06','2005-01-07','2005-01-08',
'2005-01-09','2005-01-10','2005-01-11','2005-01-12',
'2005-01-13','2005-01-14','2005-01-15','2005-01-16',
'2005-01-17','2005-01-18','2005-01-19','2005-01-20',
'2005-01-21','2005-01-22','2005-01-23','2005-01-24',
'2005-01-25','2005-01-26','2005-01-27','2005-01-28',
'2005-01-29','2005-01-30','2005-01-31')
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.26.34.20
※ 編輯: qrtt1 來自: 163.26.34.20 (08/25 14:48)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Database 近期熱門文章
PTT數位生活區 即時熱門文章