python string to date ISO 8601
Question: I am converting many obscure date formats from an old system. The dates are
unpacked/processed as strings and converted into ISO 8601 format.

This particular function attempts to convert YYMMDD0F to YYYYMMDD -- function
name says it all. Dates from the year 2000 make this messy and clearly this is
not the most pythonic way of handling them. How can I make this better using
the `dateutil.parser`?

    
    
    def YYMMDD0FtoYYYYMMDD(date):
        YY  = date[0:2]
        MM  = date[2:4]
        DD  = date[4:6]
        if int(YY) >= 78:
            YYYY = '19%s' % YY
        elif 0 <= int(YY) <= 77 and MM!='' and MM!='00': 
            YYYY = '20%s' % YY
        else:
            YYYY = '00%s' % YY
        return "%s-%s-%s" % (YYYY, MM, DD)  
    


Answer: You don't need to use `dateutil`, you can do this with
[`datetime.strptime`/`.strftime`](http://docs.python.org/2/library/datetime.html#strftime-
and-strptime-behavior):

    
    
    from datetime import datetime
    
    def YYMMDD0FtoYYYYMMDD(date):
        return datetime.strptime(date[:6], "%y%m%d").strftime("%Y-%m-%d")
    

Example usage:

    
    
    >>> YYMMDD0FtoYYYYMMDD('1403110F')
    '2014-03-11'
    

