How to list records with date from the last 10 days?

前端 未结 6 448
Happy的楠姐
Happy的楠姐 2020-12-13 01:36
SELECT Table.date FROM Table WHERE date > current_date - 10;

Does this work on PostgreSQL?

6条回答
  •  伪装坚强ぢ
    2020-12-13 02:35

    http://www.postgresql.org/docs/current/static/functions-datetime.html shows operators you can use for working with dates and times (and intervals).

    So you want

    SELECT "date"
    FROM "Table"
    WHERE "date" > (CURRENT_DATE - INTERVAL '10 days');
    

    The operators/functions above are documented in detail:

    • CURRENT_DATE
    • INTERVAL '10 days'

提交回复
热议问题