Extract date and and month from current date

Database
The Teradata Database channel includes discussions around advanced Teradata features such as high-performance parallel database technology, the optimizer, mixed workload management solutions, and other related technologies.
Fan

Extract date and and month from current date

Hello,

 

I have a column "PERIOD_ID"  in a table which is of Integer type.

 

I want to assign values in the format YYYYMM (current year and month,(current year and month) -1) to PERIOD_ID.

 

Example : PERIOD_ID in (201703,201702) 

I am able to find the current year and month but not the previous one.

 

PERIOD_ID = (sel TRIM(EXTRACT(YEAR FROM current_date))||TRIM(CASE WHEN EXTRACT(MONTH FROM current_date) >9 THEN TRIM(EXTRACT(MONTH FROM current_date)) ELSE 0||TRIM(EXTRACT(MONTH FROM current_date))END ))

 

If I add minus 1 its giving the output "2017 2.00000000000000E 000"

 

Could any one help me how to implement this.

 

Thank you in advance.

Raghu

 

 

 


Accepted Solutions
Senior Apprentice

Re: Extract date and and month from current date

Your approach is way too complicated, simpply apply TO_CHAR:

To_Char(Current_Date, 'YYYYMM,')||To_Char(Add_Months(Current_Date,-1), 'YYYYMM')
1 ACCEPTED SOLUTION
2 REPLIES
Senior Apprentice

Re: Extract date and and month from current date

Your approach is way too complicated, simpply apply TO_CHAR:

To_Char(Current_Date, 'YYYYMM,')||To_Char(Add_Months(Current_Date,-1), 'YYYYMM')
Fan

Re: Extract date and and month from current date

Thank you very much for the quick help.

Tags (1)