feed it a string from date using the format at the bottom of the script
#!/usr/bin/python
import sys
import datetime
class timediff:
strarg=""
def __init__(self, args=sys.argv[1:]):
print 'time is now: ', datetime.datetime.utcnow()
print 'your input was: ',args
self.strarg=args
def toDT(self, thenstr):
strpformat="%Y,%m,%d,%H,%M,%S"
try:
return datetime.datetime.strptime(thenstr, strpformat)
except:
print "there is something wrong with your input, did you use format like: ", strpformat
sys.exit(-1)
def thennow(self, then, now=datetime.datetime.now() ):
timediff = (now - then)
minutes = timediff.days*1440 + timediff.seconds/60
return minutes
# print number of minutes between then and .now()
# date +%Y,%m,%d,%H,%M,%S
No comments:
Post a Comment