How to convert string date interval to number of days or seconds (ISO_8601)?
Question: Is there an easy way in python to transform a string representation of a date
interval:

    
    
    P1M
    

To a timestamp or a datetime object?

Basically I need to work with date intervals according to this ISO:
<http://en.wikipedia.org/wiki/ISO_8601>

Something similar to <http://php.net/manual/en/class.dateinterval.php>


Answer: There appears to be a third-party module called
[isodate](http://pypi.python.org/pypi/isodate/) that may do what you want:

    
    
    In [1]: from isodate import parse_duration
    
    In [2]: parse_duration('P1M')
    Out[2]: isodate.duration.Duration(0, 0, 0, years=0, months=1)
    

You can also convert this object into a `datetime.timedelta` object if
necessary (providing a `start` or `end` parameter so that the proper duration
can be calculated in terms of the provided date):

    
    
    In [8]: import datetime
    
    In [9]: d = parse_duration('P1M')
    
    In [10]: d.todatetime(start=datetime.datetime.today())
    Out[10]: datetime.timedelta(31)
    

