Home > database >  MySQL. The calculation of two time lag (datetime type), the format of the time difference is a few d
MySQL. The calculation of two time lag (datetime type), the format of the time difference is a few d

Time:05-09

MySQL, computing the two time lag (datetime type), the format of the time difference is a few days for a few minutes, a few hours, what to write, bosses, answer,

CodePudding user response:

Only an idea, didn't find direct implementation scheme,

1, date to seconds, use unixtimestamp
2, is presupposed, get two dates vary the number of seconds to
3, the integer number of seconds/3600/24 day,
4, remaining/3600 hours
5, the remaining/get 60 points
6, and then the rest is second

CodePudding user response:

The select timestampdiff (day, @ d2, @ d1), timestampdiff (hour, @ d2, @ d1), timestampdiff (minute, @ d2, @ d1) %, 60 timestampdiff (second @ d2, @ d1) % 60;

CodePudding user response:

The select timestampdiff (day, @ d2, @ d1), timestampdiff (hour, @ d2, @ d1) %, 24 timestampdiff (minute, @ d2, @ d1) %, 60 timestampdiff (second @ d2, @ d1) % 60;

24 hours to %
60 minutes and seconds to %
  • Related