Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good afternoon
how can i select hours between two times eg(18:00 & 22:00)=4

this code below returns 979848 and i dont understand what this value is
can u please help me


SQL
USE [DUT_Governance_Department]
GO
/****** Object:  StoredProcedure [dbo].[StudentsRespective_Studlog]    Script Date: 10/13/2011 18:41:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Proc [dbo].[StudentsRespective_Studlog]
(@User_names char(8)
 
 )
as
select Passwords ,Students.User_names,F_name,Vote_status,Reg_status,Reg_year ,Regions.Region_name,Function_ID.Function_id,DATEDIFF(MONTH, Reg_year,GETDATE())as Month_Diff,Login_try ,DATEDIFF(hour,Try_time, GETDATE())
from Students,Regions,User_Account,Faculty,Campus,Function_ID   
where  Students.User_names =User_Account .User_names 
AND Faculty.faculty_id =Students.faculty_id
AND Campus.Campus_id=Faculty.Campus_id
AND Regions.Region_id=Campus.Region_id
AND Function_ID .Function_id =User_Account.Function_id 
AND Students.Vote_status in('N','Y')
AND Function_ID.Function_id =4
AND Students.User_names =@User_names   
Posted

1 solution

You can use a couple of methods;
Select fields from table where datefield between 'date/time1' and 'datetime2'
e.g.
Select * from Logins where LoginDate between '01-jan-2011 18:00:00' and '01-jan-2011 22:00:00'


OR
Select * from Logins where LoginDate >= '01-jan-2011 18:00:00' and LoginDate <= '01-jan-2011 22:00:00'
 
Share this answer
 
v3
Comments
sparbery 13-Oct-11 13:31pm    
i want to use values coming from the system time and time i inserted
DaveAuld 13-Oct-11 14:08pm    
Well just insert those values by calling Now() and modifying using DATEADD(); e.g. DATEADD(NOW(),hh, -4) see the docs here on DateAdd http://msdn.microsoft.com/en-us/library/ms186819.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900