0

I have a table with some example columns below:

id       creationdate                 name
1        2012-08-09 14:14:22.225      ken
2        2012-08-09 13:11:20.212      john

I want to get all rows where creationdate is older than 30 min. from now.

4

2 回答 2

5

You want to make sure the creation date value is LESS than now minus 30, not greater. The lower the value of a datetime, the older it is.

SELECT
        Id,
        creationdate,
        name
    FROM TableName
    WHERE creationdate < DATEADD(MINUTE, -30, GETDATE());
于 2012-08-09T18:45:58.060 回答
0

This will work, alternatively you could use '*' instead of listing columns if that works for your environment. If you are dealing with UTC then use GETUTCDATE().

SELECT
    Id,
    creationdate,
    name
FROM TableName
WHERE creationdate > DATEADD(MINUTE, -30, GETDATE());
于 2012-08-09T18:44:09.213 回答