Question: I have MS SQL function `DATEDIFF`

```
SELECT DATEDIFF(QQ, 0, '2018-09-05')

```

that returns 474(integer). 

What is PostgreSQL equivalent of this function ?

Answer: 
MSSQL `0` is the date `'1900-01-01'` in `DATEDIFF(QQ, 0, '2018-09-05')`, that function will get the number of `QUARTER` from `1900-01-01` to `2018-09-05`

But PostgreSQL does not have a `QUARTER` number function.

You can try to use 

1. `EXTRACT(QUARTER FROM TIMESTAMP '2018-09-05')` to get this month `QUARTER` number.
2. `date_part('year',age('2018-09-05','1900-01-01'))` get year number between 
`'2018-09-05'` and `'1900-01-01'`.

then do some calculation.

```
select (EXTRACT(QUARTER FROM TIMESTAMP '2018-09-05') + 
      date_part('year',age('2018-09-05','1900-01-01')) * 4) -1 QUARTER

```

**[Results](http://sqlfiddle.com/#!17/9eecb/20755/0)**:

```
| quarter |
|---------|
|     474 |

```
Its complicated on Postgres:

```
( (DATE_PART('year',  '2018-09-05') - DATE_PART('year', '1900-01-01')) * 12 
   + (DATE_PART('month',  '2018-09-05') - DATE_PART('month', '1900-01-01'))
) / 4

```

Additional resources: [topic](http://www.sqlines.com/postgresql/how-to/datediff)