Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Days Between solution in Uncategorized category for Days Between by capback250
import datetime
def days_diff(d1, d2):
"""
Find absolute diff in days between dates
"""
a1 = ''.join((str(d1).split(",")))[1:-1]
a2 = ''.join((str(d2).split(",")))[1:-1]
b1 = datetime.date(int(a1.split()[0]),int(a1.split()[1]),int(a1.split()[2]))
b2 = datetime.date(int(a2.split()[0]),int(a2.split()[1]),int(a2.split()[2]))
if b1 == b2:
return 0
else:
return abs(int(str(b2-b1).split()[0]))
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert days_diff((1982, 4, 19), (1982, 4, 22)) == 3
assert days_diff((2014, 1, 1), (2014, 8, 27)) == 238
assert days_diff((2014, 8, 27), (2014, 1, 1)) == 238
Aug. 1, 2015