Spaces:
Sleeping
Sleeping
File size: 539 Bytes
1d08919 c169ffd 1d08919 c169ffd 1d08919 c169ffd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from datetime import datetime
def normalize_date(date_str):
if not date_str or str(date_str).lower() in ["null", "none", "unknown"]:
return datetime.today().strftime("%Y-%m-%d")
formats = ["%Y-%m-%d", "%d-%m-%Y", "%d/%m/%Y", "%m/%d/%Y", "%Y/%m/%d", "%d %b %Y", "%B %d, %Y"]
clean = str(date_str).strip()
for fmt in formats:
try:
return datetime.strptime(clean, fmt).strftime("%Y-%m-%d")
except ValueError: continue
return datetime.today().strftime("%Y-%m-%d") |