64422506;01;45000130047;052;03;2014;1;26FEB2014;0;02APR2014
64422506;01;45000130047;052;03;2014;1;26FEB2014;0;05MAY2014
64422506;01;45000130047;052;03;2014;1;26FEB2014;0;05JUN2014
64422506;01;45000130047;052;03;2015;2;07DEC2014;0;30DEC2014
and I need to compute difference between date of lambing and date of milk recording. I thought it would be easy using python(3).
import datetime
fname=sys.argv[1]
fhand=open(fname)
for i,line in enumerate(fhand):
Dacont = line.split(sep=";")[9]
Datago = line.split(sep=";")[7]
daysfrommisebas= datetime.datetime.strptime(Dacont.lower(),'%d%b%Y') - datetime.datetime.strptime(Datago.lower(), '%d%b%Y')
and finally, print it, not forgetting to paste the strings using "+" and removing the EOL in "line":
print(line.rstrip('\n')+";"+str(daysfrommisebas.days))
No comments:
Post a Comment