Convert to Date

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
boppanakrishna
Participant
Posts: 106
Joined: Thu Jul 27, 2006 10:05 pm
Location: Mumbai

Convert to Date

Post by boppanakrishna »

Hi,

How to Convert YYYYMM to Start date for Month
EX: 201011 to 01/11/2010

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

Post by ray.wurlod »

Provide the correct format strings and use conversion functions such as DateToString() and StringToDate(). You will also need to concatenate the day number (01) to the incoming string.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Ravi.K
Participant
Posts: 209
Joined: Sat Nov 20, 2010 11:33 pm
Location: Bangalore

Post by Ravi.K »

Derivation:

'01/':DateToString(StringToDate('201011',"%yyyy%mm"),"%mm/%yyyy")
Cheers
Ravi K
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

More work may be required if the output has Date data type.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Abhi700
Participant
Posts: 20
Joined: Thu Nov 25, 2010 3:52 am
Location: Pune

Post by Abhi700 »

write a derivation


'01/':DateToString(StringToDate('201011',"%yyyy%mm"),"%mm/%yyyy")
Ravi.K
Participant
Posts: 209
Joined: Sat Nov 20, 2010 11:33 pm
Location: Bangalore

Post by Ravi.K »

Yes,If output Datatype is "Date" then it requires additional formatting based on the Database Date format or Date format.

Suppose Date format is "dd-mmm-yyyy" then derivation is as follows.

StringToDate("01/":DateToString(StringToDate('201011',"%yyyy%mm"),"%mm/%yyyy"),"%dd-%mmm-%yyyy")
Cheers
Ravi K
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Please think this through a bit more carefully.
Ravi.K wrote:StringToDate("01/":DateToString(StringToDate('201011',"%yyyy%mm"),"%mm/%yyyy"),"%dd-%mmm-%yyyy")
The inner dates use "/" delimiter, but you specified "-" in the outer StringToDate() function. This won't work!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Ravi.K
Participant
Posts: 209
Joined: Sat Nov 20, 2010 11:33 pm
Location: Bangalore

Post by Ravi.K »

oops. There is a small mistake. Thanks for the correction.

Revised Logic.

StringToDate(Convert('/','-',"01/":DateToString(StringToDate('201011',"%yyyy%mm"),"%mmm/%yyyy")),"%dd-%mmm-%yyyy")
Cheers
Ravi K
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Now re-read the original requirement, which was for "/" delimiters!
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Ravi.K
Participant
Posts: 209
Joined: Sat Nov 20, 2010 11:33 pm
Location: Bangalore

Post by Ravi.K »

Ok, Now goes to Original requirement 201011 should be marked as 01/11/2010 then if target datatype is Date.

Derivation:

StringToDate("01/":DateToString(StringToDate('201011',"%yyyy%mm"),"%mm/%yyyy"),"%dd/%mm/%yyyy")

Thanks
Cheers
Ravi K
Post Reply