python - Is there a way to handle only year in a datetime object? -


coming question here, i'm wondering if there's way in python handle year in datetime object , know year important , else has ignored?

here's example of need do:

a = date(2014, 1, 1)  a.ignore_days = true a.ignore_months = true b = date(2014, 12, 1)   if a.ignore_days , a.ignore_months , (a.year==b.year):     print("ok") 

and later on:

a = date(2014, 12, 1)  a.ignore_days = true b = date(2014, 12, 8)   if a.ignore_days , a.ignore_months , (a.year==b.year):     print("ok") else:     print("different")  if a.ignore_days , (a.year==b.year) , (a.months=b.months):     print("ok") else:     print("different")  if str(a)==str(b):     print("ok") else:     print("different") 

should output:

ok ok different 

i guess want compare years. in case can extract year form datetime object , compare them.

x = date1.year y = date2.year  if x == y:     do_my_stuff() 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -