How to get results with mysql in the last six months?

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

...where post_date < '".current_time('mysql')."'....

How to get results only for the last 6 months, i.e.:

...where post_date > '".current_time('mysql')."' - 6 MONTHS && post_date < '".current_time('mysql')."'...
+3
source share
2 answers

Use DATE_SUB (s GETDATE())

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

eg:

...  WHERE post_date > NOW() - INTERVAL 6 MONTH
+4
source

Source: https://habr.com/ru/post/1775586/


All Articles