Advertisement
ssoni

outdated.py

Jan 25th, 2024
686
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. def main():
  2.     months = ["January",    "February",    "March",    "April",    "May",    "June",    "July",    "August",    "September",    "October",    "November",    "December"]
  3.  
  4.     while True:
  5.         try:
  6.             date = input('Date: ').strip()
  7.             parts = date.split('/')
  8.             mm = int(parts[0])
  9.             dd = int(parts[1])
  10.             yyyy = int(parts[2])
  11.         except:
  12.             try:
  13.                 parts = date.split(', ')
  14.                 yyyy = int(parts[1])
  15.                 mon_dd = parts[0].split(' ')
  16.                 dd = int(mon_dd[1])
  17.                 mm = months.index(mon_dd[0])+1
  18.             except:
  19.                 continue
  20.         if (1 <= dd < 31) and (1 <= mm <= 12) and yyyy >= 0:
  21.             break
  22.  
  23.     print(f'{yyyy:04}-{mm:02}-{dd:02}')
  24.  
  25. main()
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement