python - calculating the next day from a "YYYYMMDD" formated string -


how can calculate next day string 20110531 in same yyyymmdd format? in particular case, have 20110601 result. calculating "tomorrow" or next day in static way not tough, this:

>>> datetime import date, timedelta >>> (date.today() + timedelta(1)).strftime('%y%m%d') '20110512' >>> >>> (date(2011,05,31) + timedelta(1)).strftime('%y%m%d') '20110601' 

but how can use string dt = "20110531" same result above? in advance. cheers!!

here example of how it:

import time datetime import date, timedelta  t=time.strptime('20110531','%y%m%d') newdate=date(t.tm_year,t.tm_mon,t.tm_mday)+timedelta(1) print newdate.strftime('%y%m%d') 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -