简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM