title: Using datetime.timedelta to add years
body: <p>I am doing some time calculations in Python.</p>
  
  <h3>Goal:</h3>
  
  <p>Part of this is trying to :</p>
  
  <p><em>Given a date, add time interval (X years, X months, X weeks), return date</em></p>
  
  <p>ie </p>
  
  <ul>
  <li>input args: input_time (datetime.date), interval (datetime.timedelta)</li>
  <li>return: datetime.date</li>
  </ul>
  
  <p>I looked at the datetime and <a href="https://docs.python.org/3/library/datetime.html#datetime.timedelta" rel="noreferrer">datetime.timedelta docs</a></p>
  
  <blockquote>
    <p>class datetime.timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)¶. </p>
  </blockquote>
  
  <p>These seem to work well if I want to add a certain number of hours or weeks. However, </p>
  
  <h3>Problem:</h3>
  
  <ul>
  <li>I am trying to implement an operation such as <em>date + 1 year</em> and can't figure it out </li>
  </ul>
  
  <p>E.g. </p>
  
  <pre><code>start = datetime.datetime(2000, 1, 1)
  # expected output: datetime.datetime(2001, 1, 1)
  
  
  # with the weeks, etc arguments given in timedelta, this fails unsurprisingly e.g 
  start + datetime.timedelta(weeks = 52)
  
  # returns datetime.datetime(2000, 12, 30, 0, 0)
  
  </code></pre>
  
  <h3>Question</h3>
  
  <ul>
  <li><p>Is this year-based operation possible with the basic tools of datetime - if so, how would I go about it?</p></li>
  <li><p>I realize that for the year example, I could just do <code>start.replace(year = 2001)</code>, but that approach will fail if I have months or weeks as input. </p></li>
  <li><p>From my understanding, the <em>dateutil</em> library has more advanced features, but I was not clear how well it interacts with the in-built datetime objects. </p></li>
  </ul>
  
  <p>I have reviewed this similar <a href="https://stackoverflow.com/questions/765797/python-timedelta-in-years">question</a>  but it did not help me with this. </p>
  
  <p>Any help is much appreciated!</p>
  
  <p>Running Python 3.6.5 on MacOs.</p>