odiseh
odiseh

Reputation: 26517

Working with Time portion of a DateTime Column in SQL Server2008

i have a table in SQL Server 2008 which its name is Table1. Table1 has a column named CreateDate which its data type is datetime. Now, I wanna to get records that their createDate field values are more than for instance 1 hour.

Upvotes: 0

Views: 630

Answers (3)

Mike Valenty
Mike Valenty

Reputation: 8981

This will get records that are older than one hour:

select * from Table1 where createDate < dateadd(hh, -1, getdate())

Upvotes: 0

marc_s
marc_s

Reputation: 754220

In SQL Server 2008, you should use the built-in TIME datetype as much as possible.

If you have a DATETIME column, you can easily convert it to just TIME by using:

SELECT CAST(CreateDate AS TIME) FROM Table1

That should return just the TIME part of the DATETIME column.

Marc

Upvotes: 3

anishMarokey
anishMarokey

Reputation: 11397

try with some datetime functions ,like DATEADD functions

e.g : select dateadd(hh,-1,GETDATE())

Upvotes: 1

Related Questions