Teradata date function

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
saidvs
Participant
Posts: 12
Joined: Thu Jul 28, 2005 10:41 am

Teradata date function

Post by saidvs »

Hi,

I am new to Teradata and have a problem converting date into string.
actually date is stored as varchar in teradata ex: 07/24/1922 fromat
and i want to convert into '19220724'. Please help me...

thanks,
Venkat
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Surely you can just use some combination of SUBSTRING and concatenation to produce your desired result in a SELECT statement?

In ANSI SQL this would be

Code: Select all

SELECT SUBSTRING(DATESTR FROM 7 FOR 4) || SUBSTRING(DATESTR FROM 1 FOR 2) || SUBSTRING(DATESTR FROM 4 FOR 2) FROM tablename
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
keshav0307
Premium Member
Premium Member
Posts: 783
Joined: Mon Jan 16, 2006 10:17 pm
Location: Sydney, Australia

Post by keshav0307 »

YOu search in Teradata forum.

anyway you can use this

CAST(CAST(<Date Column> AS DATE FORMAT 'YYYYMMDD' ) AS CHAR( 8 ))

e.g.
SEL CAST(CAST(CURRENT_DATE AS DATE FORMAT 'YYYYMMDD' ) AS CHAR( 8 ))
hamzaqk
Participant
Posts: 249
Joined: Tue Apr 17, 2007 5:50 am
Location: islamabad

Post by hamzaqk »

i am not sure who told you that teradata stored dates in varchar because it does not !! it stores them in an integer form always integer 4 that is

and for what you want try this:

cast ('07/24/1922' as date format 'yyyymmdd')



Teradata Certified Master V2R5
Post Reply