Python: Add a month with a specified date
Python Datetime: Exercise-23 with Solution
Write a Python program to add a month to a specified date.
Sample Solution:
Python Code:
from datetime import date, timedelta
import calendar
start_date = date(2014, 12, 25)
days_in_month = calendar.monthrange(start_date.year, start_date.month)[1]
print(start_date + timedelta(days=days_in_month))
Sample Output:
2015-01-25
Flowchart:

Python Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a Python program to get the number of days of a given month and year.
Next: Write a Python program to count the number of Monday of the 1st day of the month from 2015 to 2016.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends
- Python Interview Questions and Answers: Comprehensive Guide
- Scala Exercises, Practice, Solution
- Kotlin Exercises practice with solution
- MongoDB Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - JOINS
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join