Reputation: 1020
I have a SQL table which has a DATETIME column(EndTime)
. From my code I am passing a date and I want to get the date that has an EndTime
equal to that date. I used
SELECT MAX([EndTime]) FROM [dbo].[Table] where [EndTime]=@date
What I want is if I pass 2013-06-14 10:35
to the query it should return all the records in this time. But due to the seconds value in the table it returns only the value which has 2013-06-14 10:35:000
. How can I ignore the seconds part in the column?
Upvotes: 2
Views: 204
Reputation: 3591
You can also try below to remove seconds
SELECT MAX([EndTime])
FROM [dbo].[Table]
where DATEadd(ss,-datepart(ss,EndTime),EndTime) = @date
Upvotes: 0
Reputation: 166466
Why not try something like
SELECT MAX([EndTime])
FROM [dbo].[Table]
where [EndTime]>=@date
AND [EndTime]<DATEADD(minute,1,@date)
OR even
SELECT MAX([EndTime])
FROM [dbo].[Table]
where convert(varchar(16),EndTime,120) = @date
Upvotes: 1