Skip to content

Instantly share code, notes, and snippets.

@waltertschwe
Created February 22, 2019 13:08
Show Gist options
  • Select an option

  • Save waltertschwe/70ac1c7a6fdf9e18c6e77c7b05385770 to your computer and use it in GitHub Desktop.

Select an option

Save waltertschwe/70ac1c7a6fdf9e18c6e77c7b05385770 to your computer and use it in GitHub Desktop.
import datetime
date_string = '2019-01-22'
date_format = '%Y-%m-%d'
try:
date_obj = datetime.datetime.strptime(date_string, date_format)
print(date_obj.date())
except ValueError:
## pass 400 error here incorrect date format message
print("Incorrect data format, should be YYYY-MM-DD")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment