All Forums Database
jas 1 post Joined 03/06
07 Mar 2006
Timestamp format on teradata retrieval

I have a parameter string coming into an ETL application which is in the format MM/DD/YYYY HH:MI:SS.On the teradata database the rows I need to retrieve contain a timestamp in standard teradata format YYYY-MM-DD HH:MI:SS. I need to retrieve rows whose timestamp is later than that in the paramater, but I cannot manage to write a successful query which will convert my parameterised input into an acceptable timestamp for teradata for comparison. Any help with this would be greatly appreciated. RgdsJas

dnoeth 1928 posts Joined 11/04
07 Mar 2006

Hi Jas,select '03/07/2006 12:49:29' as ts, ts (timestamp(0), format 'MM/DD/YYYYBHH:MI:SS')Dieter

dixon 22 posts Joined 01/06
10 Mar 2006

Hi Dietercan u explain me how it is showing 2006-03-07 12:49:29 for the next part. i am amazed the format u have mentioned i.e ts (timestamp(0), format 'MM/DD/YYYYBHH:MI:SS')in the second part and the result it's showing.

Dixon

Sathish 3 posts Joined 11/05
10 Mar 2006

Hi , Default timestamp format : yyyy-mm-dd hh:mm:sssel current_timestamp 2006-03-10 07:17:58.37So specify the desired format: as ex1:select '03/07/2006 12:49:29' as ts,cast(cast(ts as timestamp(0) format 'MM/DD/YYYYBHH:MI:SS') as varchar(20))out put:03/07/2006 12:49:29 03/07/2006 12:49:29Note:Here one more varchar cast is required to display.ex2 :select cast(cast('03/07/2006 12:49:29' as timestamp(0) format 'MM/DD/YYYYBHH:MI:SS') as varchar(20)) o/p :03/07/2006 12:49:29Thanks,

yateesh 5 posts Joined 05/11
22 Jun 2011

i have one small question for you dnoeth if i want to add AM or PM in this timestamp how to write the query
for ex :
select cast(cast('03/07/2006 12:49:29 AM' as timestamp(0) format 'MM/DD/YYYYBHH:MI:SS AM') as varchar(20))
is it work in above select query,How to add Am or PM in Timestamp column? can you please help on this

dnoeth 1928 posts Joined 11/04
22 Jun 2011

select cast(cast('03/07/2006 12:49:29 PM' as timestamp(0) format 'MM/DD/YYYYBHH:MI:SSBT') as varchar(22))

'T' is used for 12-hour format and 'B' for blanks, check the "SQL Datatypes and Literals" manual, there's a chapter on FORMATs.

Dieter

benjaminpimkov 1 post Joined 11/11
30 Nov 2011

Hi

I want to have current_date in YYYYMMDDHHMISS format. But whatever do I land with seperators. Kindly help

Thanks

benjamin

 

dnoeth 1928 posts Joined 11/04
30 Nov 2011

I assume you try it in SQL Assistant:

select current_timestamp (format 'YYYYMMDDHHMISS') (char(16))

Dieter

kashifkiani 1 post Joined 11/09
19 Oct 2012

From
12/8/2010 8:00:40 PM 
8/30/2011 5:10:35 PM 
To
12/08/2010 20:00:40
08/30/2011 17:10:35
 
Suppose datetime column is start_date
Query
 
CAST(
CAST(
CAST(
CASE WHEN INDEX(START_DATE,' ')=0 THEN NULL
ELSE
CASE
WHEN SUBSTRING(START_DATE FROM 1 , INDEX(START_DATE,'/')-1 )>9
THEN SUBSTRING(START_DATE FROM 1 , INDEX(START_DATE,'/')-1 )
ELSE '0'||SUBSTRING(START_DATE FROM 1 , INDEX(START_DATE,'/')-1 ) END ||'/'||
CASE WHEN SUBSTRING(START_DATE FROM INDEX(START_DATE,'/')+1 , INDEX(SUBSTRING(START_DATE FROM INDEX(START_DATE,'/')+1),'/')-1 )>9
THEN SUBSTRING(START_DATE FROM INDEX(START_DATE,'/')+1 , INDEX(SUBSTRING(START_DATE FROM INDEX(START_DATE,'/')+1),'/')-1 )
ELSE '0'||SUBSTRING(START_DATE FROM INDEX(START_DATE,'/')+1 , INDEX(SUBSTRING(START_DATE FROM INDEX(START_DATE,'/')+1),'/')-1 )
END ||'/'||
SUBSTRING (SUBSTRING(START_DATE FROM INDEX(START_DATE,'/')+1) FROM INDEX(SUBSTRING(START_DATE FROM INDEX(START_DATE,'/')+1),'/')+1,4)
||' '||
CASE WHEN SUBSTRING( SUBSTRING(START_DATE FROM INDEX(START_DATE ,' ')+1) FROM 1, INDEX(SUBSTRING(START_DATE FROM INDEX(START_DATE ,' ')+1),':')-1 )>9
THEN SUBSTRING( SUBSTRING(START_DATE FROM INDEX(START_DATE ,' ')+1) FROM 1)
ELSE '0'||SUBSTRING( SUBSTRING(START_DATE FROM INDEX(START_DATE ,' ')+1) FROM 1)
END
END
AS TIMESTAMP(0) FORMAT 'mm/dd/yyyybhh:mi:ssbt')
AS TIMESTAMP(0) FORMAT 'mm/dd/yyyybhh:mi:ss')
AS VARCHAR(23))

You must sign in to leave a comment.