How to add number of days in postgresql datetime

前端 未结 2 1668
无人及你
无人及你 2020-12-23 18:28

I have a following table projects.

id title        created_at                     claim_window
1  Project One  2012-05-08 13:50:09.924437     5
         


        
2条回答
  •  隐瞒了意图╮
    2020-12-23 19:22

    This will give you the deadline :

    select id,  
           title,
           created_at + interval '1' day * claim_window as deadline
    from projects
    

    Alternatively the function make_interval can be used:

    select id,  
           title,
           created_at + make_interval(days => claim_window) as deadline
    from projects
    

    To get all projects where the deadline is over, use:

    select *
    from (
      select id, 
             created_at + interval '1' day * claim_window as deadline
      from projects
    ) t
    where localtimestamp at time zone 'UTC' > deadline
    

提交回复
热议问题