Solved

how to subtract a time in SQL server

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

786 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