1def valid_date(s):
2 try:
3 return datetime.strptime(s, "%Y-%m-%d")
4 except ValueError:
5 msg = "Not a valid date: '{0}'.".format(s)
6 raise argparse.ArgumentTypeError(msg)
7
8parser.add_argument("-s",
9 "--startdate",
10 help="The Start Date - format YYYY-MM-DD",
11 required=True,
12 type=valid_date)