/*--------------------------time to intercept-----------------------------------*/Select Left(CONVERT(varchar( -),'2017-11-24 19:25:30.740', -), -)--back to 2017-11-24 19:25--separate interceptionSelect DatePart(Hour,'2017-11-24 19:25:30.740')--Return hours/*-----------------Two time periods of difference, accurate to seconds (can be used for countdown)----------------------*/SELECT DATEDIFF(Second,'2009-8-25 12:15:12','2009-9-1 7:18:20')--returns the number of seconds differenceSELECT DATEDIFF(Minute,'2009-9-1 6:15:12','2009-9-1 7:18:20')--return minutes of differenceSELECT DATEDIFF( Day,'2009-8-25 12:15:12','2009-9-1 7:18:20')--returns the difference in number of daysSELECT DATEDIFF(Hour,'2009-8-25 12:15:12','2009-9-1 7:18:20')--returns the difference between hours--The number of minutes to find two time difference--Method OneSELECT CONVERT(INT,DATEDIFF( Day,'2017-11-24 19:00:00','2017-11-24 19:01:00')* -* -)+CONVERT(INT,DATEDIFF(Hour,'2017-11-24 19:00:00','2017-11-24 19:01:00')* -)+CONVERT(INT,DATEDIFF(Minute,'2017-11-24 19:00:00','2017-11-24 19:01:00'))--Method TwoDeclare @day int --daysDeclare @hour int --hoursDeclare @min int --pointsDeclare @sec int --secondsDeclare @alls int Select GETDATE()Set @alls=DateDiff(S,'2017-11-24 19:00:00',GETDATE())--difference between Time 1 and time 2 (seconds)Set @day=@alls/86400 --daysSet @hour=(@alls-@day*86400)/3600 --hoursSet @min=(@alls-@day*86400-@hour*3600)/ - --pointsSet @sec=@alls-@day*86400-@hour*3600-@min* - --secondsSelect CAST(@day as varchar(5))+'days'+CAST(@hour as varchar(2))+'hours'+CAST(@min as varchar(2))+'points'+CAST(@sec as varchar(2))+'seconds'Cha
SQL Server Two time period difference and time intercept to cent