To select a date in yyyymmdd format

General
Enthusiast

To select a date in yyyymmdd format

Hi,

 

I need the output of the below query in single column, can anyone please help me in this?

 

SELECT CURRENT_DATE- INTERVAL '2' YEAR as lastdt, cast(cast(lastdt as timestamp(0) format 'YYYYMMDD') as varchar(20))

 

 

Thanks!

  • Teradata
2 REPLIES
Senior Apprentice

Re: To select a date in yyyymmdd format

Don't use Interval syntax for years, it will fail on Feb. 29th.

 

TO_CHAR(ADD_MONTHS(CURRENT_DATE,-24), 'yyyymmdd')
Enthusiast

Re: To select a date in yyyymmdd format

Thanks for your reply and guidance.