I have tried a sample code with 2 datetime inputs and I calculated the difference between them in minutes. It is working fine but I am not able to subtract every input in columns of excel. Please help.
What I have tried:
from datetime import datetime
date_formats = ["%Y-%m-%d %H:%M:%S", "%d-%m-%Y %H:%M:%S", "%m-%d-%Y %H:%M:%S", "%Y/%m/%d %H:%M:%S", "%d/%m/%Y %H:%M:%S", "%m/%d/%Y %H:%M:%S", "%Y.%m.%d %H:%M:%S", "%d.%m.%Y %H:%M:%S", "%m.%d.%Y %H:%M:%S", "%d %b %Y %H:%M:%S", "%b %d %Y %I:%M%p", "%y-%m-%d %H:%M:%S", "%d-%m-%y %H:%M:%S", "%m-%d-%y %H:%M:%S", "%y/%m/%d %H:%M:%S", "%d/%m/%y %H:%M:%S", "%m/%d/%y %H:%M:%S", "%y.%m.%d %H:%M:%S", "%d.%m.%y %H:%M:%S", "%m.%d.%y %H:%M:%S", "%b %d %Y %H:%M:%S", "%Y-%m-%d %H:%M", "%d-%m-%Y %H:%M", "%m-%d-%Y %H:%M", "%d-%m-%Y %H:%M", "%B %d %Y %H:%M:%S"]
#match = []
d1 = input()
d2 = input()
for fmt in date_formats:
try:
a = datetime.strptime(d1, fmt)
b = datetime.strptime(d2, fmt)
d = (b-a)
day = d.days
#print(d)
minutes = day * 24 * 60
print(minutes,'minutes')
break
except ValueError as e:
continue