How to get the date N days ago in Python

Posted 网名还没想好

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了How to get the date N days ago in Python相关的知识,希望对你有一定的参考价值。

from datetime import datetime, timedelta

N = 2

date_N_days_ago = datetime.now() - timedelta(days=N)

print datetime.now()
print date_N_days_ago

Results:

2010-10-16 00:06:06.000201
2010-10-14 00:06:06.000107

For more information see the timedelta documentation

以上是关于How to get the date N days ago in Python的主要内容,如果未能解决你的问题,请参考以下文章