简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM