Answers for "python subtract 6 months from date time"

3

datetime.timedelta months

from datetime import timedelta
from dateutil.relativedelta import relativedelta

end_date = start_date + relativedelta(months=delta_period) + timedelta(days=-delta_period)
Posted by: Guest on June-30-2020
0

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
Posted by: Guest on August-16-2021

Code answers related to "python subtract 6 months from date time"

Python Answers by Framework

Browse Popular Code Answers by Language