postgresql Postgres Tip and Tricks Difference between two date timestamps month wise and year wise

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

Monthwise difference between two dates(timestamp)

select 
    (
        (DATE_PART('year', AgeonDate) - DATE_PART('year', tmpdate)) * 12 
        +
        (DATE_PART('month', AgeonDate) - DATE_PART('month', tmpdate))
    ) 
from dbo."Table1"

Yearwise difference between two dates(timestamp)

select (DATE_PART('year', AgeonDate) - DATE_PART('year', tmpdate)) from dbo."Table1"


Got any postgresql Question?