Code to check for expiration date, from one python scripts output -


i have pre made python script calls c# script within address server. output of 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 able check today's date against "license expiration date". i've looked on datetime , stumped. know can't check date against integer, cant it. have 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 comparing datetime objects using strptime create datetime object expiration date string , comparing datetime.now().date(), strftime creates strings compared lexicographically can incorrect results:

from datetime import datetime, date datet = '2015-12-15'  expirationdate = datetime.strptime(datet,"%y-%m-%d").date() = date.today() if expirationdate >= now:     .... 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -