How do you do date math that ignores the year?

前端 未结 8 1711
梦谈多话
梦谈多话 2020-11-28 11:14

I am trying to select dates that have an anniversary in the next 14 days. How can I select based on dates excluding the year? I have tried something like the following.

8条回答
  •  孤街浪徒
    2020-11-28 11:44

    I found a way to do it.

    SELECT EXTRACT(DAYS FROM age('1999-04-10', '2003-05-12')), 
           EXTRACT(MONTHS FROM age('1999-04-10', '2003-05-12'));
     date_part | date_part 
    -----------+-----------
            -2 |        -1
    

    I can then just check that the month is 0 and the days are less than 14.

    If you have a more elegant solution, please do post it. I'll leave the question open for a bit.

提交回复
热议问题