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

How do I search through a folder for the filename that matches a regular expression using Python?

python regex

I am having some difficulty writing a function that will search through a directory for a file that matches a specific regular expression (which I have compiled using 're.compile'). So my question ...

smoothdivscroll logo parade dont start

javascript carousel

I just add a logo parade to the top of this website. After having sort out all the errors, and review all the code, the parade dont start.... i cannot find what it's like that

Implement Repository Pattern in Asp.Net MVC with SOA architecture

wcf unit-testing asp.net-mvc-4 architecture repository-pattern

We have starting new project in our company. We finalize the architecture as follows

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.