We help IT Professionals succeed at work.

get dates difference in hours and minutes

arcross
arcross asked
on
248 Views
Last Modified: 2012-05-07
Hello, ive got to date fields in my db with date and time and id like another column showing the difference in hours an minutes. in hte format hh:mm
Comment
Watch Question

Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT

Commented:
SELECT  TO_CHAR(TO_DATE(TRUNC(MOD(date2-date1,1)*86400),'SSSSS'), 'HH24:MI:SS') time
from TABLE

cast ((datediff(hh,begin_time,end_time)) + ':' + (datediff(mm,begin_time,end_time)) as varchar(10))
Kyle AbrahamsSenior .Net Developer
CERTIFIED EXPERT

Commented:
ignore the first, use the cast.
Database Consultant
CERTIFIED EXPERT
Top Expert 2009
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Kevin CrossChief Technology Officer
CERTIFIED EXPERT
Most Valuable Expert 2011
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
these two work...thanks to aneeshattingal (a little format there) and mwvisa1
1) SELECT CONVERT(varchar(5),endtime - starttime,108) from timesheet

2) SELECT starttime,endtime,CONVERT(VARCHAR(5), DATEADD(mi, DATEDIFF(mi, starttime, endtime), 0), 108) FROM timesheet

ged325 yours gave me this error..
"Conversion failed when converting the varchar value ':' to data type int."


thanks everyone!
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.