how to convert mm/dd/yyyy hh:mm:ss into CCYYMMDD

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
pattemk
Participant
Posts: 84
Joined: Wed May 16, 2007 4:04 pm

how to convert mm/dd/yyyy hh:mm:ss into CCYYMMDD

Post by pattemk »

hi everyone

can anyone help me how to convert mm/dd/yyyy hh:mm:ss to CCYYMMDD

INPUT DATATYPE--> VARCHAR(24)
OUTPUT DATATYPE-->VARCHAR(8)

PLZ HELP

THANK YOU
ds_developer
Premium Member
Premium Member
Posts: 224
Joined: Tue Sep 24, 2002 7:32 am
Location: Denver, CO USA

Post by ds_developer »

You could try:

DATE[7,4]:DATE[1,2]:DATE[4,2]

The DATE I am referring to is the name of the date field coming into the transformer.

John
pattemk
Participant
Posts: 84
Joined: Wed May 16, 2007 4:04 pm

thanks, but still one question

Post by pattemk »

[quote="ds_developer"]You could try:

DATE[7,4]:DATE[1,2]:DATE[4,2]

The DATE I am referring to is the name of the date field coming into the transformer.

John[/quote]

hi john

thanks for replyin but in my input dates are like 5/4/1998, 11/5/2001,5/21/1996,11/31/1994 and your formula works fine for 11/31/1994 how to do with other kinds
pattemk
Participant
Posts: 84
Joined: Wed May 16, 2007 4:04 pm

thanks, but still one question

Post by pattemk »

[quote="ds_developer"]You could try:

DATE[7,4]:DATE[1,2]:DATE[4,2]

The DATE I am referring to is the name of the date field coming into the transformer.

John[/quote]

hi john

thanks for replyin but in my input dates are like 5/4/1998, 11/5/2001,5/21/1996,11/31/1994 and your formula works fine for 11/31/1994 how to do with other kinds
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Use the FIELD function to parse out your 3 string elements, i.e. FIELD(In.Date,'/',3) to get the year portion. Then format those strings to the correct length since you are getting variable length columns and finally concatenate them to the resulting format.
G SHIVARANJANI
Participant
Posts: 137
Joined: Sun Jan 07, 2007 11:17 pm
Location: VISAKHAPATNAM

Re: thanks, but still one question

Post by G SHIVARANJANI »

Use this way

Str("0", 2-Len(trim(SRC_DATE)['/',1,1])) : trim(SRC_DATE)['/',1,1]:Str("0", 2-Len(trim(SRC_DATE)['/',2,1])) : trim(SRC_DATE)['/',2,1]:Str("0", 2-Len(trim(SRC_DATE)['/',3,1])) : trim(SRC_DATE)['/',3,1]


Here SRC_DATE is the date field from source

cheers


pattemk wrote:
ds_developer wrote:You could try:

DATE[7,4]:DATE[1,2]:DATE[4,2]

The DATE I am referring to is the name of the date field coming into the transformer.

John
hi john

thanks for replyin but in my input dates are like 5/4/1998, 11/5/2001,5/21/1996,11/31/1994 and your formula works fine for 11/31/1994 how to do with other kinds
Shivaranjani
G SHIVARANJANI
Participant
Posts: 137
Joined: Sun Jan 07, 2007 11:17 pm
Location: VISAKHAPATNAM

Re: thanks, but still one question

Post by G SHIVARANJANI »

Sorry u need CCYYMMDD

So Use this Way
trim(SRC_DATE)['/',3,1]:Str("0", 2-Len(trim(SRC_DATE)['/',2,1])) : trim(SRC_DATE)['/',2,1]:Str("0", 2-Len(trim(SRC_DATE)['/',1,1])) : trim(SRC_DATE)['/',1,1]

G SHIVARANJANI wrote:Use this way

Str("0", 2-Len(trim(SRC_DATE)['/',1,1])) : trim(SRC_DATE)['/',1,1]:Str("0", 2-Len(trim(SRC_DATE)['/',2,1])) : trim(SRC_DATE)['/',2,1]:Str("0", 2-Len(trim(SRC_DATE)['/',3,1])) : trim(SRC_DATE)['/',3,1]


Here SRC_DATE is the date field from source
Shivaranjani
Post Reply