Solved

how to subtract a time in SQL server

Posted on 2004-09-19
3
809 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Expert Comment

by:paelo
ID: 12097135
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
ID: 12098564
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
ID: 12099866
Tahanks nigelrivett

my problum in sloved
thanks again

0

Featured Post

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

623 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