Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

sql server - How do I get the minute difference between 2 times in T SQL?

How do I get the "minutes" difference between 2 times in T SQL? I tried DATEDIFF, but it obviously wants dates. This would be the difference in minutes between 2 times in a day. Any suggestions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

DateDiff not only work with Date datatype it even accepts TIME datatype.

Even if your datatype is nvarchar it will work but it should be a valid time.

Simple Demo

create table time_test(a nvarchar(50),b nvarchar(50))

insert time_test values ('4:00 PM','4:30 PM')

select datediff(minute,a,b) from time_test --30

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...