How do I find the nth day of the next month in Python?
datetime, python
Solution
The `dateutil` library is useful for this:
from dateutil.relativedelta import relativedelta
from datetime import datetime
# Where day is the day you want in the following month
dt = datetime.now() + relativedelta(months=1, day=20)
Problem
I am trying to get the date `delta` by subtracting today's date from the `nth` day of the next month. ``` delta = nth_of_next_month - todays_date print delta.days ``` How do you get the date object for the 1st (or 2nd, 3rd.. nth) day of the next month. I tried taking the month number from the date object and increasing it by 1. Which is obviously a dumb idea because 12 + 1 = 13. I also tried adding one month to today and tried to get to the first of the month. I am sure that there is a much more efficient way of doing this.