This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author petedmarsh
Recipients petedmarsh
Date 2015-04-07.17:29:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1428427753.85.0.794213637884.issue23884@psf.upfronthosting.co.za>
In-reply-to
Content
Hello,

Reasonably frequently I find myself needing to pass a date as a command line argument to a Python script I've written. Currently, argparse does not have a built support for dates - this adds a new class to argparse (much like the existing FileType) that parses arguments to datetime.date instances.

Example:

      >>> parser = argparse.ArgumentParser()
      >>> parser.add_argument('--start', type=argparse.DateType('%d/%m/%Y))
      >>> parser.add_argument('end', type=argparse.DateType())
      >>> parser.parse_args(['--start', '01/02/2015', '2015-01-03'])
      Namespace(end=datetime.date(2015, 1, 3), start=datetime.date(2015, 1, 2))


I think this would be a useful addition to the standard library, a quick Google shows that many people roll their own version of this anyway.

Support for datetime.datetime and perhaps even datetime.timedeltas might be good too, but date/times get a bit more complicated (timezones in general and varying support for the '%z' format string which is required to default to an ISO8601 date time).

Cheers,

Pete
History
Date User Action Args
2015-04-07 17:29:13petedmarshsetrecipients: + petedmarsh
2015-04-07 17:29:13petedmarshsetmessageid: <1428427753.85.0.794213637884.issue23884@psf.upfronthosting.co.za>
2015-04-07 17:29:13petedmarshlinkissue23884 messages
2015-04-07 17:29:13petedmarshcreate