replace mm/dd/yyyy with mm/01/yyyy

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
hondaccord94
Participant
Posts: 46
Joined: Tue Aug 10, 2004 11:07 am
Location: Mclean VA

replace mm/dd/yyyy with mm/01/yyyy

Post by hondaccord94 »

Hi Gurus,

I am trying to write a build-op(first time) in C++ for some business transformations. One of the requirements is, I am getting date from a flat file in the format mm/dd/yyyy and the requirement is to load the target with mm/01/yyyy. Can anybody suggest a way to do this in the build-op. If possible please let me know how should I do this using datastage also.

Thanks for your time
pneumalin
Premium Member
Premium Member
Posts: 125
Joined: Sat May 07, 2005 6:32 am

Post by pneumalin »

I am guru :wink: , but the following messages might become a token for you to break the ice...

You may not need the BuildOp since it is usually used to build a customed stage for your designer. To achieve this date transformation, you just need to create a PX routine using c code. There is a sample folder in DS CD, you shall find the clue to complete the job..

Cheers!
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Hello Accord,

this operation is not difficult in either Px or Server and you do not need to do any c++ or other coding to effect it.

In a transform just specify In.InDate[1,3]:'00':In.InDate[6,5] in both flavors to get the required format.
hondaccord94
Participant
Posts: 46
Joined: Tue Aug 10, 2004 11:07 am
Location: Mclean VA

Post by hondaccord94 »

Thanks for the info. I will look into that.
But I am not writting a build-op just for that date transformation alone, I have whole bunch of other transformations also. Anyways I will check that sample folder. And if you have any clue abt the C++ code please let me know.
hondaccord94
Participant
Posts: 46
Joined: Tue Aug 10, 2004 11:07 am
Location: Mclean VA

Post by hondaccord94 »

Thank you very much. I will check that.
ArndW wrote:Hello Accord,

this operation is not difficult in either Px or Server and you do not need to do any c++ or other coding to effect it.

In a transform just specify In.InDate[1,3]:'00':In.InDate[6,5] in both flavors to get the required format.
bcarlson
Premium Member
Premium Member
Posts: 772
Joined: Fri Oct 01, 2004 3:06 pm
Location: Minnesota

Post by bcarlson »

Try this:

Code: Select all

// First, load input date string into a date variable
APT_Date tmpDate1;
tmpDate1.set(in.dtfromfile, "%mm/%dd/%yyyy");

// Then, create new temp variable using Y and M pieces of first date,
// and 1 for day.  The class APT_Date has a constructor that we can 
// use:  APT_Date(int year, int month, int day).  Also, APT_Date has functions for returning pieces of the date.
APT_Date tmpDate2(tmpDate1.year(), tmpDate1.month(), 1);

// Finally, assign your output date field
out.outputDate = tmpDate2;

// ... or your output string field
out.outputDateString = tmpDate2.asString("%mm/%dd/%yyyy");
I am sure there are many ways to do what you're looking for, but this works.
hondaccord94
Participant
Posts: 46
Joined: Tue Aug 10, 2004 11:07 am
Location: Mclean VA

Post by hondaccord94 »

Thank you very much.That is working....
bcarlson wrote:Try this:

Code: Select all

// First, load input date string into a date variable
APT_Date tmpDate1;
tmpDate1.set(in.dtfromfile, "%mm/%dd/%yyyy");

// Then, create new temp variable using Y and M pieces of first date,
// and 1 for day.  The class APT_Date has a constructor that we can 
// use:  APT_Date(int year, int month, int day).  Also, APT_Date has functions for returning pieces of the date.
APT_Date tmpDate2(tmpDate1.year(), tmpDate1.month(), 1);

// Finally, assign your output date field
out.outputDate = tmpDate2;

// ... or your output string field
out.outputDateString = tmpDate2.asString("%mm/%dd/%yyyy");
I am sure there are many ways to do what you're looking for, but this works.
Post Reply