Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in a table having the fields of starttime & endtime ,I want to fetch only the records having starttime & endtime of same days.
Posted
Comments
Mahendra.p25 25-Mar-11 6:58am    
Not clear please elaborate

Try:
SELECT * FROM myTable WHERE YEAR(startDate)=YEAR(endDate) AND MONTH(startDate)=MONTH(endDate) AND DAY(startDate)=DAY(endDate)


(sorry about that; I misread your question...)
 
Share this answer
 
Comments
Mahendra.p25 25-Mar-11 7:04am    
starttime & endtime
OriginalGriff 25-Mar-11 7:09am    
So change the names! :laugh:
Costica U 25-Mar-11 7:25am    
My 5
Try this
SQL
select  *
from    MyTable
where   convert(varchar(10),starttime,112)=convert(varchar(10),endtime,112)
-- convert(varchar(10),starttime,112) removes HH:MM:SS from the starttime column: YYYYMMDD
 
Share this answer
 
One possibility is truncate the time away:
SELECT * 
FROM TableName
WHERE CAST(StartTime AS DATE) = CAST(EndTime AS DATE)
 
Share this answer
 
SQL
DECLARE @StartTime [DateTime]
SET @StartTime = '01/01/2010 10:30:45'
DECLARE @EndTime [DateTime]
SET @EndTime = '01/01/2010 10:45:51'
SELECT
CASE WHEN DATEDIFF(second, @StartTime, @EndTime) / 3600 < 10 THEN '0' ELSE '' END
+ RTRIM(DATEDIFF(second, @StartTime, @EndTime) / 3600)
+ ':' + RIGHT('0'+RTRIM((DATEDIFF(second, @StartTime, @EndTime) % 3600) / 60),2)
+ ':' + RIGHT('0'+RTRIM((DATEDIFF(second, @StartTime, @EndTime) % 3600) % 60),2)
AS [HH:MM:SS]


it will give you the difference between two times then check
whether it is less then or Equals to 24 hours if it matches then

display that task
 
Share this answer
 

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