Database
Fan

## Want to know the difference between the working of teradata statements

Hi Team,

I am an ETL developer, we are working on project where we need to extract data from Teradata,

The requirement is like I want to calculate the no. of months  between two dates , add 1 to it and then compare.

its like A = (Difference between St_dt and End_dt) +1

what I am using is :

A =(MONTHS_BETWEEN(St_dt, ENd_dt) (FORMAT '9999') (CHAR 8)) +1

What  they are suggesting :

A-1 = (st_dt -end_dt)month(4)

2 REPLIES
Junior Contributor

## Re: Want to know the difference between the working of teradata statements

Whatever you need to get the expected result :)

MONTHS_BETWEEN returns a result including a fraction. Your calculation is inefficient because you cast to a string and then back to an int, better use `CAST(MONTHS_BETWEEN(end_dt, st_dt) AS INT).`

And Interval calculations are based on different logic (like subtracting months numbers), simply check the differences using a sample.

Fan

## Re: Want to know the difference between the working of teradata statements

Thank you Dieter,

Your response helps a lot, in doing the RCA of  one issue. Thanks a lot!!