Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the same day of next month of a given day in python using datetime

i know using datetime.timedelta i can get the date of some days away form given date

daysafter = datetime.date.today() + datetime.timedelta(days=5) 

but seems no datetime.timedelta(month=1)

like image 802
icn Avatar asked Feb 12 '10 05:02

icn


People also ask

How do you get the next day in Python?

datetime() to format the given date . Then, Use givenDate + datetime. timedelta(days=1) to add one day from the given date and print result as next date in python.


1 Answers

Use dateutil module. It has relative time deltas:

import datetime from dateutil import relativedelta nextmonth = datetime.date.today() + relativedelta.relativedelta(months=1) 

Beautiful.

like image 134
nosklo Avatar answered Sep 27 '22 17:09

nosklo