datetime.timedelta months
from datetime import timedelta
from dateutil.relativedelta import relativedelta
end_date = start_date + relativedelta(months=delta_period) + timedelta(days=-delta_period)
datetime.timedelta months
from datetime import timedelta
from dateutil.relativedelta import relativedelta
end_date = start_date + relativedelta(months=delta_period) + timedelta(days=-delta_period)
python subtract month from date
# Normally deltatime is one of good way to manipulate date and time
# with fine details, but since a month can have different nubmer a days
# relativedelta is a good option;
from datetime import datetime
from dateutil.relativedelta import relativedelta
# Take a timestamps
datetime_now = datetime.now()
print("Current Date and time :- ", datetime_now)
>>> Current Date and time :- 2021-08-16 11:59:49.802902
# Create a delta time
datetime_delta = relativedelta(months=+1)
# subtract datetime_delta
datetime_new = datetime_now - datetime_delta
print("Current Date and time minus Delta datetime :- ", datetime_new)
>>> Current Date and time minus Delta datetime :- 2021-07-16 11:59:49.802902
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us