Is there a direct way to ignore parts of a python datetime object?
<p>I'm trying to compare two datetime objects, but ignoring the year. For example, given</p>

<pre><code>a = datetime.datetime(2015,07,04,01,01,01)
b = datetime.datetime(2016,07,04,01,01,01)
</code></pre>

<p>I want a == b to return True by ignoring the year. To do a comparison like this, I imagine I could just create new datetime objects with the same year like:</p>

<pre><code>c = datetime.datetime(2014,a.month,a.day,a.hour,a.minute,a.second)
d = datetime.datetime(2014,b.month,b.day,b.hour,b.minute,b.second)
</code></pre>

<p>However, this doesn't seem very pythonic. Is there a more direct method to do a comparison like what I'm asking?</p>

<p>I'm using python 3.4.</p>

<pre><code>(a.month, a.day, a.hour, a.minute, a.second == 
 b.month, b.day, b.hour, b.minute, b.second)
</code></pre>

<p>A less explicit method is to compare the corresponding elements in the time tuples:</p>

<pre><code>a.timetuple()[1:6] == b.timetuple()[1:6]
</code></pre>

python datetime