Solved

how to subtract a time in SQL server

Posted on 2004-09-19
3
791 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
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

860 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