SQL Get all records older than 30 days

后端 未结 3 410
走了就别回头了
走了就别回头了 2020-12-24 10:20

Now I\'ve found a lot of similar SO questions including an old one of mine, but what I\'m trying to do is get any record older than 30 days but my table field is unix_timest

相关标签:
3条回答
  • 2020-12-24 10:57

    Try something like:

    SELECT * from profiles WHERE to_timestamp(last_login) < NOW() - INTERVAL '30 days' 
    

    Quote from the manual:

    A single-argument to_timestamp function is also available; it accepts a double precision argument and converts from Unix epoch (seconds since 1970-01-01 00:00:00+00) to timestamp with time zone. (Integer Unix epochs are implicitly cast to double precision.)

    0 讨论(0)
  • 2020-12-24 11:14

    Unless I've missed something, this should be pretty easy:

    SELECT * FROM profiles WHERE last_login < NOW() - INTERVAL '30 days';
    
    0 讨论(0)
  • 2020-12-24 11:14

    How about

    SELECT * from profiles WHERE last_login < VALUEOFUNIXTIME30DAYSAGO
    

    or

    SELECT * from profiles WHERE last_login < (extract(epoch from now())-2592000)
    

    Have a look at this post:

    https://dba.stackexchange.com/questions/2796/how-do-i-get-the-current-unix-timestamp-from-postgresql

    and this

    http://www.epochconverter.com/

    0 讨论(0)
提交回复
热议问题