Discussion Locked

getting the time from an sql DateTime field

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I need to get the rows from a table which has a datetime attribute. The datetime attribute gives the date and time of insertion of a given row. I want to get the rows which have been inserted say within the last five seconds.To do this i have to get the time of the datetime attribute.
Assume that the date is irrelevant since the table will only hold the insertions within the current day.
Is there a simple way of doing this?

1 reply

by texasconnelly

This should work:

select *
from TABLE_NAME
where DATETIME_COLUMN between dateadd(ss, -5, getDate()) and getDate()

This discussion is closed to new replies.