Select today's (since midnight) timestamps only

前端 未结 5 1672
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 14:24

I have a server with PostgreSQL 8.4 which is being rebooted every night at 01:00 (don\'t ask) and need to get a list of connected users (i.e. their timestamps are u.lo

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 15:24

    An easy way of getting only time stamps for the current day since 01:00 is to filter with CURRENT_DATE + interval '1 hour'

    So your query should look like this:

    SELECT u.login, u.id, u.first_name
    FROM pref_users u
    WHERE u.login > u.logout AND
          u.login > CURRENT_DATE + interval '1 hour'
    ORDER BY u.login;
    

    Hope that helps.

提交回复
热议问题