Solved

how to subtract a time in SQL server

Posted on 2004-09-19
3
756 Views
Last Modified: 2008-02-01
how i subtract a time(hours & minuts) like
i have a time1 09:00 AM and time2 11:30 AM the differance is 2:30 hours
i use DateDiff(hh,time1,time2) they return 2 only but i need hours witt minuts like (2:30)
how i use a Query for this prblum
i use this query in asp.net

please help me .
0
Comment
Question by:ISKPatel
3 Comments
 
LVL 9

Expert Comment

by:paelo
Comment Utility
Try:

SELECT CONVERT(varchar,+DATEDIFF(hh,time1,time2))+':'+CONVERT(varchar,DATEDIFF(n,time1,time2)) As TimeDiff
FROM yourtable

-Paul.
0
 
LVL 18

Accepted Solution

by:
nigelrivett earned 50 total points
Comment Utility
time2 - time1 will do it if they are both datetimes.
If not you can convert
convert(datetime,time2) - convert(datetime,time1)
then format the result maybe?
convert(varchar(5),convert(datetime,time2) - convert(datetime,time1),108)

0
 

Author Comment

by:ISKPatel
Comment Utility
Tahanks nigelrivett

my problum in sloved
thanks again

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now