Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #subtract #months #date
ADD COMMENT
Topic
Name
5+2 =