MySql difference between two timestamps in days?

前端 未结 7 1173
既然无缘
既然无缘 2020-11-30 01:14

How can I get the difference between two timestamps in days? Should I be using a datetime column for this?


I switched my column to datetime. Simple subtraction doesn\'t
7条回答
  •  攒了一身酷
    2020-11-30 01:25

    I know is quite old, but I'll say just for the sake of it - I was looking for the same problem and got here, but I needed the difference in days.

    I used SELECT (UNIX_TIMESTAMP(DATE1) - UNIX_TIMESTAMP(DATE2))/60/60/24 Unix_timestamp returns the difference in seconds, and then I just divide into minutes(seconds/60), hours(minutes/60), days(hours/24).

提交回复
热议问题