Answers for "get previous date in python"

5

get yesterday date python

>>> from datetime import datetime, timedelta
>>> datetime.strftime(datetime.now() - timedelta(1), '%Y-%m-%d')
'2015-05-26'
Posted by: Guest on July-28-2020
1

get last year of today python

import datetime
from dateutil.relativedelta import relativedelta

last_year = (datetime.datetime.now()-relativedelta(years=1)).strftime("%Y-%m-%d")
Posted by: Guest on June-22-2021

Code answers related to "get previous date in python"

Python Answers by Framework

Browse Popular Code Answers by Language