Assuming I have a select statement:
SELECT COUNT(*), wedding, DATE_FORMAT(weddate, '%y %m %d') FROM weddingtable
I want to make it such that I could subtract 1 from the month it would return: for example:
SELECT COUNT(*), wedding, DATE_FORMAT(weddate, '%y %m-1 %d') FROM weddingtable
It appears to just append "-1" to the month integer instead of actually subtracting one from the month. How do I accomplish this? (in other words, where it would normally return 5 in place of %m, it would return 4, etc.)
Note: For January, I would expect in place of %m, it would be "0".
Your solution can be derived from: Subtract month and day mysql
e.g. (DATE_SUB(curdate(), INTERVAL 1 MONTH)
SELECT COUNT(*), wedding, DATE_SUB(weddate,INTERVAL 1 MONTH) FROM weddingtable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With