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>def cmp(a,b):
 return (a &gt; b) - (a &lt; b)

d1=(2015,7,4,1,1,1)
d2=(2016,7,4,1,1,1)

cmp(list(d1)[1:],list(d2)[1:])
</code></pre>

<p>Returns 0 - they are the same, i.e. 0 differences</p>

<pre><code>d1=(2015,7,4,1,1,1)
d2=(2015,2,4,1,1,1)

cmp(list(d1)[1:], list(d2)[1:])
</code></pre>

<p>returns -1, there is a difference.</p>

python datetime