Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python subtract months from date

# To subtract or add months from date you can use the third party dateutil module.

import datetime
from dateutil.relativedelta import relativedelta

date = datetime.datetime.strptime("2021-12-31", "%Y-%m-%d")
date2 = date - relativedelta(months=1)
print date2
Comment

PREVIOUS NEXT
Code Example
Python :: how to install matplotlib in python 
Python :: matplotlib is required for plotting when the default backend "matplotlib" is selected. 
Python :: remove all pyc 
Python :: max columns in python 
Python :: python order dataframe according to date time 
Python :: disable images selenium python 
Python :: is pythin a real coding language 
Python :: python print timestamp 
Python :: python get path string 
Python :: delete column pandas dataframe 
Python :: install xgboost 
Python :: python reload lib jupyter notebook %reload 
Python :: python print traceback from exception 
Python :: install imageio 
Python :: python write json to file utf8 
Python :: pylsp install 
Python :: make tkinter btn disable 
Python :: set recursion limit python 
Python :: python check if folder exists 
Python :: tuple negative indexing in python 
Python :: set axis labels python 
Python :: python write text file 
Python :: pygame.rect parameters 
Python :: axis number size matplotlib 
Python :: python delete contents of file 
Python :: update python ubuntu 
Python :: ImportError: matplotlib is required for plotting when the default backend "matplotlib" is selected. 
Python :: DeprecationWarning: executable_path has been deprecated, please pass in a Service object 
Python :: pytorch plt.imshow 
Python :: choice random word in python from a text file 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =