I need to calculate an end date based on todays date and a number of months. For example, todays date 04/01/2010 and the number of months is 6. Are there any functions I can use to do some math that would return “10/01/2010”?
Also, I think it’s important to note that I am storing the result in MySQL as a “DATETIME” so I guess I would have to do something with the time as well… ???
Thanks!
If you are storing the result as a DATETIME in MySQL, then the following code is probably what you want:
strtotime() turns a string into a timestamp, and will work from the current time with a relative value by default.
date()will use that timestamp, and the format string above will give you a MySQL-friendly TIMESTAMP value.e.g.: