I have a pre made Python script that calls a C# script within an address server. The output of this script is:
Build Number : 2381
Database Date : 2015-07-15
Database Expiration Date: 10-31-2015
License Expiration Date : 2016-05-03
Build Number : 2381
Database Date : 2015-06-15
Database Expiration Date: 2015-12-15
License Expiration Date : 2016-05-03
I want to be able to check today's date against the "License Expiration Date". I've looked over datetime and I am stumped. I know I can't check a date against an integer, but I just cant get it. This is what I have so far.
import time
print (time.strftime("%Y-%m-%d"))
datet = '2015-12-15'
class Timedelta(object):
@property
def isoformat(self):
return str()
ExpirationDate = time.strftime("%Y-%m-%d")
if ExpirationDate >= datet:
print 'Renew License Soon'
elif ExpirationDate == datet:
print 'Renew License Immediately'
else:
print "License OK"
quit()
You should be comparing datetime objects using strptime to create the datetime object from your expiration date string and comparing it to datetime.now().date(), strftime creates strings which will be compared lexicographically so you can get incorrect results:
from datetime import datetime, date
datet = '2015-12-15'
ExpirationDate = datetime.strptime(datet,"%Y-%m-%d").date()
now = date.today()
if ExpirationDate >= now:
....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With