Don’t try to be more clever then everybody else

Just noticed, that my home-brew method of calculating “last month” had a small glitch

monat=((MONTH(NOW())+10)%12)+1 AND jahr=YEAR(NOW())

This clever — but only in 11 month. And as we have full moon 12 times a year one should better use MySQL’s way of calculating dates:

monat=MONTH(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) AND jahr=YEAR(DATE_SUB(CURDATE(), INTERVAL 1 MONTH)) 
Advertisements