The dates are in format "YYYYMMDD" and I want it in "YYYYMMDD-(1)", i.e previous day.
For example consider date 20080101 the previous date would be 20071231.
Is there any built in function to do this ?
The dates are in format "YYYYMMDD" and I want it in "YYYYMMDD-(1)", i.e previous day.
For example consider date 20080101 the previous date would be 20071231.
Is there any built in function to do this ?
You can perform this transformation in 3 steps:
datetime
.datetime
object to str
.Here is an example:
from datetime import datetime, timedelta
x = '20080101'
f = '%Y%m%d'
res = (datetime.strptime(x, f) - timedelta(days=1)).strftime(f)
# '20071231'