Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

how to subtract a time in SQL server

Posted on 2004-09-19
3
Medium Priority
?
818 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 200 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

722 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