views:

33

answers:

2

I have a timestamp field [SubmissionDate], which defaults to current_timestamp, and i was wondering how do i query my database in such a fashion that for example i get only shown all entries submitted on a certain year and month? Something like:

SELECT * FROM DNA_entrys
WHERE `SubmissionDate`.month = February
AND `SubmissionDate`.year = 2004

Should be an elementary operation but i couldn't find a quick answer on that

+1  A: 

Does this work?

SELECT * FROM DNA_entrys
WHERE MONTH(SubmissionDate) = 2
AND YEAR(SubmissionDate) = 2004
eumiro
+1  A: 
SELECT * FROM DNA_entrys
WHERE month(`SubmissionDate`) = 2
AND year(`SubmissionDate`) = 2004

tho i suggest:

SELECT * FROM DNA_entrys
WHERE `SubmissionDate` between '2004-02-01' and ('2004-03-01' - INTERVAL 1 SECOND)

latter allows use of indexes, which makes query faster if you have ithat field indexed.

Imre L
+1: Nicely done, the update handles leap years
OMG Ponies