Count months between two timestamp on postgresql?

前端 未结 11 1158
一个人的身影
一个人的身影 2021-02-01 14:50

I want to count the number of months between two dates.

Doing :

SELECT TIMESTAMP \'2012-06-13 10:38:40\' - TIMESTAMP \'2011-04-30 14:38:40\';
         


        
11条回答
  •  清酒与你
    2021-02-01 15:36

    Try this solution:

    SELECT extract (MONTH FROM age('2014-03-03 00:00:00'::timestamp, 
    '2013-02-03 00:00:00'::timestamp)) + 12 * extract (YEAR FROM age('2014-03-03   
    00:00:00'::timestamp, '2013-02-03 00:00:00'::timestamp)) as age_in_month;
    

提交回复
热议问题