MySQL - datediff days (保留几位小数)

MySQL - datediff days (keep several decimal)

请设置下面的table。当我使用 datediff(StartDate, SubmittedOn) 时,我只得到 int 类型的天数,这是不准确的。那么如何获得迟到的呢?谢谢你。

StartDate        SubmittedOn        what I get using datediff   what I am tring to get
9/7/2016 13:12  9/1/2016 0:00        6                          6.550520833
9/1/2016 16:22  9/1/2016 0:00        0                          0.682048611
9/9/2016 13:30  9/1/2016 0:00        8                          8.562708333
9/9/2016 13:31  9/1/2016 0:00        8                          8.563472222
9/9/2016 16:08  9/1/2016 0:00        8                          8.672407407
9/2/2016 16:08  9/1/2016 0:00        1                          1.672685185
9/2/2016 16:01  9/1/2016 0:00        1                          1.667465278

尝试使用 TIMEDIFF 而不是 DATEDIFF。

more here

上一个问题好像关闭不正确

无论如何,您想以较小的时间单位计算差异并转换为天数。例如:

select t.*,
       timestampdiff(second, startdate, submittedon) / (24 * 60 * 60) as days_with_fraction
from t;