Count number of days between two dates

前端 未结 10 733
暗喜
暗喜 2020-12-12 23:26

How do I count the number of days between these two dates?

start_date = Date.parse \"2012-03-02 14:46:21 +0100\"
end_date =  Date.parse \"2012-04-02 14:46:21         


        
10条回答
  •  庸人自扰
    2020-12-12 23:54

    To have the number of whole days between two dates (DateTime objects):

    ((end_at - start_at).to_f / 1.day).floor
    

提交回复
热议问题