0

I have a script that get the date from datetime, and the date from whois service:

import time
from datetime import datetime
import whois
#date
url='testurl.com'
now = datetime.now()
date1 = datetime.strftime(nowstr,'%Y-%m')
#whois
domain = whois.whois(url)
datestr = domain.creation_date
date2 = datetime.strftime(datestr, '%Y-%m')

When i calculate the difference:

diff = datetime.strptime(date1,'%Y-%m') - datetime.strptime(date2,'%Y-%m')
print diff

it gives me output like:

5451 days, 0:00:00

How can i get the Output in the format of Years and months(in my case, 14y 11m)?

Kara
  • 6,115
  • 16
  • 50
  • 57
Alex A
  • 107
  • 2
  • 11

1 Answers1

1

Take a look at this post. I believes it answers your question. It shows both using standard and non-standard python libraries.

Community
  • 1
  • 1
chirinosky
  • 4,438
  • 1
  • 28
  • 39