how to calculate month difference from two different columns in Sql Developer?

Viewed 1970

I want to calculate month difference in same table from 2 different columns. In other words, I have 2 different columns that include dates and I would like to see their month difference in Sql Developer. Is there any way to do that?

Thank you.

2 Answers

for mysql : The DATEDIFF function can give you the number of days between two dates.

for oracle: months_between

sample:

SELECT months_between(column1,column2)
FROM Table

for the month differnce the standard sql is DATEDIFF, in this function you must pass 3 params, if you must calculate the difference from 2 columns, c1 and c2, you must do this query

SELECT DATEDIFF(month,c1 , c2)
FROM T
WHERE ...

Here the documentation of datediff https://www.w3schools.com/sql/func_sqlserver_datediff.asp

if you use oracle you can use also

SELECT months_between(c1,c2)
FROM T
WHERE ...

This is the documentation https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions089.htm

Related