Skip to content

Instantly share code, notes, and snippets.

@duchenpaul
Created March 6, 2020 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duchenpaul/0ef331ac8c52e0abadd4b235d22d2758 to your computer and use it in GitHub Desktop.
Save duchenpaul/0ef331ac8c52e0abadd4b235d22d2758 to your computer and use it in GitHub Desktop.
validate date in a file
from datetime import datetime
with open('test.txt') as f:
date_list = f.read().split('\n')
date_list = [ x.replace('"', '').strip() for x in date_list if x]
for x in date_list:
try:
datetime.strptime(x, '%m/%d/%Y')
except Exception as e:
print(x)
else:
pass
finally:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment