-2

End Goal: To compare a whois output to the users computer date, to see if a website was made within a month.

import whois
from datetime import datetime
w = whois.whois('www.google.com')
w = w.creation_date 
print (w)

This is where I need your help, I want to compare that output to the users computer date. How can I do that.....

  • 3
    According to the docs, ``whois`` already provides ``datetime``s. Your "users computer date" can also be provided as ``datetime``s (you even import the tool for it). What problem do you have comparing the "whois ``datetime``s" against the "computer ``datetime``s"? – MisterMiyagi Aug 02 '21 at 11:19
  • Oh I didn't know that LMAO, I just want to compare the whois creation_date to the users computer date and then have it pick up if the website was made within a month of the user computer date – Full On Gamer Aug 02 '21 at 11:22
  • Well, ``print (w)`` should have already told you it's a ``datetime``. Again, what problem do you have working with that? – MisterMiyagi Aug 02 '21 at 11:26
  • Then you don't want to compare to the computer's clock. You want to compare to a date a month ago. – Klaus D. Aug 02 '21 at 11:28
  • little bit confused, the problem come when i want to see if the website was made within a month. Just don't know how to do it.. – Full On Gamer Aug 02 '21 at 11:29
  • @KlausD. Smart. How could I make it just compare to a date a month ago? (Like with code) – Full On Gamer Aug 02 '21 at 11:31
  • 1
    Does this answer your question? [How to compare two dates?](https://stackoverflow.com/questions/8142364/how-to-compare-two-dates) – MisterMiyagi Aug 02 '21 at 11:31
  • Some what, just trying to apply it to my code – Full On Gamer Aug 02 '21 at 11:33
  • Does this answer your question? [Python check if date is within 24 hours](https://stackoverflow.com/questions/39080155/python-check-if-date-is-within-24-hours/39080237) – MisterMiyagi Aug 02 '21 at 11:34
  • if `print( type(w.creation_date) )` gives `` then `w.creation_date.date() == datetime.today().date()`. Or if you `from datetime import date` then `... = date.today()` – furas Aug 02 '21 at 11:46

1 Answers1

0

You can use datetime to get the current time of the system then put your logic to compare it to the whois data.

import whois
from datetime import datetime

w = whois.whois('www.google.com')
w = w.creation_date
n = datetime.now()

w = str(w[0])
n = str(n)
print(w[0:10])
print(n[0:10])

var = (datetime.strptime(n[0:10], "%Y-%m-%d") - datetime.strptime(w[0:10], "%Y-%m-%d")).days

if var > 31:
    print("more than a month")

You can surely take up from there. The two last print() will give you yyyy-mm-dd

EDIT : this gives you the number of days between the two dates. You can use an if to print out a message.

v015h3bn1k
  • 98
  • 11