How can I calculate the number of months between YYYYMM integer values in PostgreSQL? -


how can calculate number of months between 2 yyyymm integer values in postgresql?

data:

| date1  | date2  | |--------|--------| | 201608 | 201702 | | 201609 | 201610 | 

desired output:

| date1  | date2  | monthsbetweeninclusive | monthsbetweenexclusive | |--------|--------|------------------------|------------------------| | 201608 | 201702 | 7                      | 6                      | | 201609 | 201610 | 2                      | 1                      | 

i have looked @ postgresql date function documentation i'm unable find solution operates on yyyymm integer values.

with t(d1,d2) (values(201608,201702),(201609,201610)) select   *,   ((d2/100*12)+(d2-d2/100*100))-((d1/100*12)+(d1-d1/100*100)) t; 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -