开发者

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

开发者 https://www.devze.com 2023-01-25 11:07 出处:网络
I have a basic query fetching results for all results earlier than today: ...where post_date < \'\"开发者_运维知识库.current_time(\'mysql\').\"\'....

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

精彩评论

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

关注公众号