Not sure about PHP but I think that the DATE_SUB() function in MySQL will allow you to subtract months. Something like this:Does any of you came across a PHP function to be able to remove 3 months from a specific date.
I need to find records in the DB based on start date YEAR-MONTH-01 minus 3months and end date YEAR-MONTH-31, 30 or 28 minus 3 month depending on the dates given.
Perhaps using the DATE_SUB to generate the month and then using a limiter on the DATE function might work or alternatively (in a major kludge) use a number of DATE_SUB queries to generate the limits. Subtracting 3 months gives the lower limit, subtracting two months and then a day gives the upper limit. Very inelegant but it may work.I am not sure if that will work with MySQL version but the problem I came across was with the date format I need which unfortunately has to be exact
e.g.
start date 2008-01-01
end date 2008-03-31 or 30 or 28/29 (February)
I could manage the start date easily (already done) as all months starts with 01 but the end date seems to be a pain and I thought I might ask if there is a function already available as I might have to spend few hours to create one.
PHP:<?php $3monthsago = mktime(0, 0, 0, date("m")-3, date("d"), date("y")); echo "3 months ago was ".date("m/d/y", $3monthsago ); ?>
=date("F",mktime(6, 0, 0, date("m")-3, 1, date("y")));