SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 hour and minute
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

peace
Constraint Violating Yak Guru

373 Posts

Posted - 10/04/2012 :  23:03:54  Show Profile  Reply with Quote
fromDate-->2011-03-06 13:05:00
toDate-->2011-03-06 20:05:00
how can i count the hour and minute together?
it should be 7 hour 0 minute

tkizer
Almighty SQL Goddess

USA
35953 Posts

Posted - 10/05/2012 :  00:56:14  Show Profile  Visit tkizer's Homepage  Reply with Quote
You can use the DATEDIFF function for this.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

mani_1234
Starting Member

India
24 Posts

Posted - 10/05/2012 :  00:57:57  Show Profile  Reply with Quote
create table #t
( fromdate datetime ,
todate datetime )

insert #t
select '2011-03-06 13:05:00','2011-03-06 20:05:00 ' union all
select '2011-03-06 13:05:00','2011-03-06 20:06:00 '
union all select '2011-03-06 13:05:00','2011-03-07 16:06:00 '
union all select '2011-03-06 09:00:00','2011-03-06 18:15:00 '


select * from #t

select convert(varchar(5),datediff(HOUR ,fromdate,todate)) + ' hour '+
convert(Varchar(5),DATEDIFF (Minute,fromdate,todate)%60) +' Minute ' +
convert(Varchar(5),DATEDIFF (SECOND ,fromdate,todate)%60) +' Second '
from #t
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000