How can I subtract a length-of-time from a boost gregorian date?
Let’s say I construct a date as follows:
boost::gregorian::date Today(2012, 02, 13);
I would like to do Today – N weeks from Today – N Months from Today – N years and get a valid date after subtraction.
To get one week prior to today, just use
To get the previous month you can do.
But the same day of the previous month might not exist. For example, if today were March 30, there is no February 30th, but boost will “snap” to the end of the month in the case of March 30 – months(1) and give you Feb 28th (or Feb 29th in leap years).
The classes are all part of the boost::gregorian namespace.