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


沒有留言:

張貼留言

[ JS 常見問題 ] Javascript Date output formatting

Source From  Here   Question   I need to  capture the Now() date and time in the YYYY/mm/dd hh:m:sec format . It needs to be in GMT time. Ho...