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>In [70]: a
Out[70]: datetime.datetime(2015, 7, 4, 0, 0)

In [71]: b
Out[71]: datetime.datetime(2016, 7, 4, 0, 0)

In [72]: def my_date_cmp(a, b):
   ....:     return a.replace(year = b.year) == b
   ....: 

In [73]: my_date_cmp(a, b)
Out[73]: True
</code></pre>

python datetime