2017年10月9日 星期一

[ Python 常見問題 ] How to get the date N days ago in Python

Source From Here 
Below will use datetime & timedelta to get the date N days ago: 
>>> from datetime import datetime, timedelta 
>>> N = 2 // Calculate 2 days ago from now on 
>>> date_N_days_ago = datetime.now() - timedelta(days=N) 
>>> print datetime.now() 
2017-10-10 12:22:18.817720 
>>> print date_N_days_ago 
2017-10-08 12:22:07.384718


沒有留言:

張貼留言

[Linux 常見問題] How to set a file size limit for a directory?

Source From   Here   Question   I   have a directory on my system which is used for a specific reason by applications and users , but I   d...