troubleshooting Question

SQL subtract two times to get minutes - SQL Server 2008

Avatar of robthomas09
robthomas09 asked on
Microsoft SQL ServerMicrosoft SQL Server 2005Microsoft SQL Server 2008SQL
3 Comments2 Solutions618 ViewsLast Modified:
Hello experts.

I have two string variables that I need to subtract to find their times, and need some help with the syntax please.

DECLARE @S1 varchar(10)  = '09:15 AM'
DECLARE @S2 varchar(10)  = '10:15 AM'

set @S3 = @s1 - @s2

select @s3 -- would like the answer to be 60 (minutes).



Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros