开发者

how do I fetch results with mysql for the past six months?

I have a basic query fetching results for all results earlier than today:

...where post_date < '"开发者_运维知识库.current_time('mysql')."'....

How do I only fetch results for the past 6 months, i.e.:

...where post_date > '".current_time('mysql')."' - 6 MONTHS && post_date < '".current_time('mysql')."'...


Use DATE_SUB (and GETDATE())

...where post_date > DATE_SUB(GETDATE(), INTERVAL 6 MONTH) ...


eg:

...  WHERE post_date > NOW() - INTERVAL 6 MONTH
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜