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
 DATEDIFF - Adding the half hour!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sampcuk
Starting Member

32 Posts

Posted - 08/04/2008 :  06:18:57  Show Profile  Reply with Quote
This may be a very sill question... I have an SQL that returns the amount of time missed for a course i.e. 9am-10am then it returns '1'. However if the course runs 9am-10.30am it still returns '1' and not '1.5'...

Can anyone help with this? Have been onto books online and am still stumped!

SELECT (RTRIM(Employee.FORENAME)+" "+eMPLOYEE.SURNAME) AS Custom,
Employee.DEPARTMENT AS Department,
Trainrec.COURSE_REF AS Course_ref,
Trainrec.COURSENAME AS Coursename,
Trainrec.STATUS AS Status,
Trainrec.STARTTIME AS Starttime,
Trainrec.FINISHTIME AS Finishtime,
((SELECT DATEDIFF(HOUR,TRAINREC.STARTTIME,TRAINREC.FINISHTIME))) AS TimeMissed
FROM dbo.EMPLOYEE AS Employee
INNER JOIN dbo.TRAINREC AS Trainrec
ON Employee.EMPLOY_REF = Trainrec.EMPLOY_REF
WHERE (((Trainrec.STATUS LIKE '%CANCELLED%' OR Trainrec.STATUS LIKE '%ABSENT%')
AND (Trainrec.STARTTIME >= '28/04/2008')))

khtan
In (Som, Ni, Yak)

Singapore
17638 Posts

Posted - 08/04/2008 :  06:21:13  Show Profile  Reply with Quote
find the datediff in minute and divide by 60.0


KH
Time is always against us

Go to Top of Page

sampcuk
Starting Member

32 Posts

Posted - 08/04/2008 :  06:22:30  Show Profile  Reply with Quote
Hi,
Yes I did this which does return the required result but only in minutes. Is there no way to return the value in hours with the half hour included?
Thanks
Go to Top of Page

elancaster
A very urgent SQL Yakette

United Kingdom
1208 Posts

Posted - 08/04/2008 :  06:25:41  Show Profile  Reply with Quote
if you divide it by 60.0 (as suggested) the result will not be in minutes... 90 / 60.0 = 1.5

Em
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22756 Posts

Posted - 08/04/2008 :  06:26:24  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
select datediff(minute,'2008-08-04 9:00:00','2008-08-04 10:30:00')/60.0


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17638 Posts

Posted - 08/04/2008 :  06:26:29  Show Profile  Reply with Quote
quote:
Originally posted by sampcuk

Hi,
Yes I did this which does return the required result but only in minutes. Is there no way to return the value in hours with the half hour included?
Thanks


divide by 60.0 will give you in hour


KH
Time is always against us

Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22756 Posts

Posted - 08/04/2008 :  06:26:54  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sampcuk
Starting Member

32 Posts

Posted - 08/04/2008 :  06:43:12  Show Profile  Reply with Quote
Thank you ALL for your help
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.08 seconds. Powered By: Snitz Forums 2000