I’m rather new to ASP.NET and SQL, so I’m having a tough time trying to figure out how to compare two time columns. I have a timestamped column and then a Now() column in an .mdb database. I need to have a gridview display records that are “Greater than or equal to 3 hours” from the timestamp. Any idea how I can accomplish this?
Share
The Transact-SQL timestamp data type is a binary data type with no time-related values.
So to answer your question: Is there a way to get DateTime value from timestamp type column?
The answer is: No
You need another column of
datetime2type and use>operator to for comparison. You might want to set default value ofgetutcdate()to set it when each row is inserted.UPDATE:
Since the column is of
datetimetype and nottimestamptype (there is a type in SQL Server calledtimestamp, hence the confusion) you can just doWHERE [TimeCalled] <= DATEADD(hour, -3, GETDATE())Make sure your server is running in the same timezone as your code. It may be safer to store all dates in UTC. In that case use
GETUTCDATEinstead onGETDATE