subtract dates with time module
barronmo
barronmo at gmail.com
Wed Apr 2 16:07:30 EDT 2008
Thanks for the help everyone. I ended up with the following:
def OBweeks(ptID):
qry = 'SELECT short_des FROM problems WHERE patient_ID = %s;' %
(ptID)
results = EMR_utilities.getAllData(qry)
for items in results:
r = re.search('\d\d\d\d-\d\d-\d\d', str(items))
if r:
edc = datetime.date(*map(int, r.group().split('-')))
pregnancy = datetime.timedelta(weeks=-40)
conception = edc + pregnancy
howfar = datetime.date.today() - conception
weeks, days = divmod(howfar.days, 7)
return '%s %s/7 weeks' % (weeks, days)
else: pass
Mike
More information about the Python-list
mailing list