how to add/subtract 2 days in the target day in python?

I have a problem in adding or subtracting 2 days to the target day... here is my code :

import datetime

target_date = datetime.date(2011,2,7)

thanks

Answers


Use datetime.timedelta:

import datetime
target_date = datetime.date(2011,2,7)

delta = datetime.timedelta(days=2)
new_date = target_date - delta

print new_date # 2011-02-05

Need Your Help

MVC 5: Loading content area via Ajax and modify browser url

jquery asp.net-mvc asp.net-mvc-4 jquery-plugins asp.net-mvc-5

In my _Layout.cshtml page I have few links on left side of the page and a main content area on the right side of the page, when clicking the links only the content area should get updated. I don’t ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.