I think the function you're looking for is MONTH(date)
. You'll probably want to use 'YEAR' too.
Let's assume you have a table named things
that looks something like this:
id happend_at
-- ----------------
1 2009-01-01 12:08
2 2009-02-01 12:00
3 2009-01-12 09:40
4 2009-01-29 17:55
And let's say you want to execute to find all the records that have a happened_at
during the month 2009/01 (January 2009). The SQL query would be:
SELECT id FROM things
WHERE MONTH(happened_at) = 1 AND YEAR(happened_at) = 2009
Which would return:
id
---
1
3
4
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…