1 先取秒 再将秒计算为天、时、分、秒 

declare @startdate datetime
declare @enddate datetime
set @startdate='2019-11-12 14:23:26'
set @enddate='2019-11-14 10:25:32'
declare @secondTotal int
declare @dateNum int
declare @hourNum int
declare @minuteNum int
declare @secondNum int

select @secondTotal=DATEDIFF (SECOND,@startdate,@enddate);--秒 158526
select @dateNum=@secondTotal/(60*60*24);--天 1
select @hourNum=(@secondTotal-(60*60*24*@dateNum))/(60*60);--小时 20
select @minuteNum=(@secondTotal-(60*60*24*@dateNum+60*60*@hourNum))/60;---分钟 2
select @secondNum=(@secondTotal-(60*60*24*@dateNum+60*60*@hourNum+60*@minuteNum))--秒

select @dateNum as 天,@hourNum as 小时,@minuteNum as 分钟,@secondNum as 秒

 

 2 mysql 中

select timestampdiff(DAY,'2019-11-12 14:23:26','2019-11-14 10:25:32') as dnum;


select timestampdiff(HOUR,'2019-11-12 14:23:26','2019-11-14 10:25:32')
-timestampdiff(DAY,'2019-11-12 14:23:26','2019-11-14 10:25:32')*24 as hnum;


select timestampdiff(Minute,'2019-11-12 14:23:26','2019-11-14 10:25:32')
-timestampdiff(HOUR,'2019-11-12 14:23:26','2019-11-14 10:25:32')*60 as munm;


select timestampdiff(Second,'2019-11-12 14:23:26','2019-11-14 10:25:32')
-timestampdiff(Minute,'2019-11-12 14:23:26','2019-11-14 10:25:32')*60 as snum;

 

 

相关文章:

  • 2021-12-26
  • 2021-12-31
  • 2021-11-25
  • 2021-10-29
  • 2022-12-23
  • 2021-07-31
  • 2022-12-23
  • 2021-12-09
猜你喜欢
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2021-12-15
相关资源
相似解决方案