sagivmal sagivmal - 4 months ago 22
SQL Question

Calculating time difference between 2 dates in Teradata

I'm trying to calculate time difference (in months) between the current date, and the date the customer opened his account (only for those who joined in January 2012).

I try to use

current_date
and
cast
, but I think my problem is in my date field which is in the following format: dd/mm/yyyy

I'm working on Teradata.

Your help will be appreciated.

Answer

You can try like this:

SELECT CURRENT_DATE - CAST('2016-06-06' AS DATE) MONTH(4);

and if your date is in dd/mm/yyyy format then you can try like

SELECT CURRENT_DATE - cast(myDate as date format 'YYYY-MM-DD') MONTH(4);