I am doing sort of a code migration from Python to Teradata:
The python code is this:
max = min(datetime.today(), date timedelta(days=90))
where date variable holds a date.
However, in Teradata, I know this min function won't work the same way. And, I have to get the 'date' using a select statement.
SEL min(SELECT CURRENT_TIMESTAMP, SEL MAX(DTM) INTERVAL '90' DAY FROM BILLS) as max
Those select statements individually run correct. Only thing is I want the minimum of those two dates. Also, the 'SELECT CURRENT_TIMESTAMP
' is generating output like 2022-11-16 12:18:37.120000 00:00
. I only want 2022-11-16 12:18:37
. How can this be done in a single query?
Thank you.
CodePudding user response:
Were you looking for this one?
SELECT LEAST(13, 6);
SELECT LEAST( to_char(date1,'YYYYMMDD'), to_char(date2,'YYYYMMDD') );
CodePudding user response:
No reason to convert to VARCHAR. Assuming DTM is TIMESTAMP(0), all you need is:
SELECT LEAST(CAST(CURRENT_TIMESTAMP(0) AS TIMESTAMP(0)),
MAX(DTM) INTERVAL '90' DAY)
FROM BILLS;