How to calculate number of days between two given dates?

前端 未结 13 1312
梦如初夏
梦如初夏 2020-11-22 06:29

If I have two dates (ex. \'8/18/2008\' and \'9/26/2008\'), what is the best way to get the number of days between these two dates?

13条回答
  •  臣服心动
    2020-11-22 06:39

    everyone has answered excellently using the date, let me try to answer it using pandas

    dt = pd.to_datetime('2008/08/18', format='%Y/%m/%d')
    dt1 = pd.to_datetime('2008/09/26', format='%Y/%m/%d')
    
    (dt1-dt).days
    

    This will give the answer. In case one of the input is dataframe column. simply use dt.days in place of days

    (dt1-dt).dt.days
    

提交回复
热议问题