开发者

Query MySQL database with timestamp

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
开发者_JS百科

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


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.


Does this work?

SELECT * FROM DNA_entrys
WHERE MONTH(SubmissionDate) = 2
AND YEAR(SubmissionDate) = 2004
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜