DATEIFF function

Database
Enthusiast

DATEIFF function

hi guys,

 

need help with conversion from SQL to TERADATA:

declare @StartDate datetime = convert(datetime,DATEDIFF(DAY, 0, GETDATE()))

declare @EndDate datetime = convert(datetime,DATEDIFF(DAY, 0, GETDATE()+ @DaysToEvent))

 

TNX:)

3 REPLIES
Enthusiast

Re: DATEIFF function

i have the same issue - also need help:)

Junior Contributor

Re: DATEIFF function

SQL Server's GETDATE is equivalent to Teradata/Standard SQL's CURRENT_TIMESTAMP:

GETDATE() = CURRENT_TIMESTAMP(2) -- Timestamp including Time Zone
GETDATE() = CAST(CURRENT_TIMESTAMP(2) AS TIMESTAMP(2)) -- Timestamp without Time Zone
CONVERT (DATE, GETDATE()) = CURRENT_DATE -- Date only
CONVERT (TIME, GETDATE()) = CURRENT_TIME(2) -- Time only

And this DATEDIFF simply calculates the begin of a day, i.e. midnight:

convert(datetime,DATEDIFF(DAY, 0, GETDATE())) = CAST(CURRENT_DATE AS TIMESTAMP(2))
convert(datetime,DATEDIFF(DAY, 0, GETDATE()+ @DaysToEvent)) = CAST(CURRENT_DATE + @DaysToEvent AS TIMESTAMP(2))

If you always calculate midnight you better use DATE instead of TIMESTAMP.

 

Btw, SQL means Standard SQL, not Microsoft SQL Server, although MS indoctrination is obviously quite successful :-)

 

 

Enthusiast

Re: DATEIFF function

Great! I succeeded! Thank you:)