Date Conversion

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.
Enthusiast

Date Conversion

Hi,

i try convert from SQL to TERA :

DECLARE @DateIn DATETIME = GETDATE()

DECLARE @StartNumDays INT

DECLARE @EndNumDays INT

declare @DaysBack int = 180

declare @DaysBackDate int = convert(int,convert(varchar(20),getdate()-@DaysBack,112))

DECLARE @STARTDATE DATETIME = cast(convert(char(10),dateadd(day, -@StartNumDays, @DateIn ), 101 )AS datetime)

DECLARE @ENDDATE DATETIME = cast(convert(char(10),dateadd(day, -@EndNumDays, @DateIn ), 101 )AS datetime)

 

someone know how to write it correct.

 

Thanks & Best Regards

 

 

2 REPLIES
Junior Contributor

Re: Date Conversion

declare @DaysBackDate int = convert(int,convert(varchar(20),getdate()-@DaysBack,112))
= CAST(CURRENT_DATE - @DaysBack AS INT) + 19000000

DECLARE @STARTDATE DATETIME = cast(convert(char(10),dateadd(day, -@StartNumDays, @DateIn ), 101 )AS datetime)
= CAST(CURRENT_DATE - @StartNumDays AS TIMESTAMP) 

Are you working with Dates or Timestamps?

Enthusiast

Re: Date Conversion

With dates its easy. i work with timestamps.
Tx!