I am using the datetime Python module. I am looking to calculate the date 6 months from the current date. Could someone give me a little help doing this?
The reason I want to generate a date 6 months from the current date is to produce a Review Date. If the user enters data into the system it will have a review date of 6 months from the date they entered the data.
So, here is an example of the
dateutil.relativedelta
which I found useful for iterating through the past year, skipping a month each time to the present date:As with the other answers, you have to figure out what you actually mean by "6 months from now." If you mean "today's day of the month in the month six years in the future" then this would do:
I use this function to change year and month but keep day:
You should write:
Well, that depends what you mean by 6 months from the current date.
Using natural months:
Using a banker's definition, 6*30:
From this answer, see parsedatetime. Code example follows. More details: unit test with many natural-language -> YYYY-MM-DD conversion examples, and apparent parsedatetime conversion challenges/bugs.
The above code generates the following from a MacOSX machine:
With Python 3.x you can do it like this:
but you will need to install python-dateutil module:
I think it would be safer to do something like this instead of manually adding days: