How to convert integer into date object python?
Question: I am creating a module in python, in which I am receiving the date in integer
format like `20120213`, which signifies the 13th of Feb, 2012. Now, I want to
convert this integer formatted date into a python date object.

Also, if there is any means by which I can subtract/add the number of days in
such integer formatted date to receive the date value in same format? like
subtracting 30 days from `20120213` and receive answer as `20120114`?


Answer: This question is already answered, but for the benefit of others looking at
this question I'd like to add the following suggestion: Instead of doing the
slicing yourself as suggested above you might also use strptime() which is
(IMHO) easier to read and perhaps the preferred way to do this conversion.

    
    
    import datetime
    s = "20120213"
    s_datetime = datetime.datetime.strptime(s, '%Y%m%d')
    

