Complex Date Conversion Problem

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
bmsq
Premium Member
Premium Member
Posts: 32
Joined: Mon Oct 30, 2006 9:19 pm

Complex Date Conversion Problem

Post by bmsq »

Hi guys,

I've got a problem with converting dates in either a Column Import or Transformer that I hope someone will be able to help me out with.

The input date string is %dd %mmm and I need to convert this to a Date type using a second date as the cut off period. My initial thought was to get the year from the cut off date and append it to the source string to get %dd %mmm %yyyy. This doesn't work as I need to check if the source %dd %mmm is before the cut off period, in which case the appended year would be one year lower than that of the cut off date.

I also though that I could append the the cut off year to the source date and then convert is to a Date. This date would not be correct, but I could use it to check if it was before or after the cut off date. If before, then I use the cut off year-1. However, I think this would cause conversion errors when if the date was 29 Feb because this is only valid on a leap year.

I hope that make sense. Any help would be appreciated.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

First please make clear whether this is a server job question (as marked) or a parallel job question (as per the forum in which you have posted). The answer will be markedly different based on job type. If it's in a job sequence, let us know that too.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
bmsq
Premium Member
Premium Member
Posts: 32
Joined: Mon Oct 30, 2006 9:19 pm

Post by bmsq »

Server? How did that get in the title, I selected parallel....

Anyway, sorry about the confusion. This is a Parallel problem, I'd just use DS Basic or OCONV/ICONV if this were server.

Cheers,
Barry
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

Convert your InDate and CutOffDate to this format - %mm%dd (mmdd - string). Now follow the below logic in stage variable:

If MMDD of InDate is greater or equal to MMDD of CutOffDate then append CCYY else append CCYY - 1
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
bmsq
Premium Member
Premium Member
Posts: 32
Joined: Mon Oct 30, 2006 9:19 pm

Post by bmsq »

Thanks Josh,

I thought that might be the way I'd need to do it. Is there any easy way to perform the conversion from %dd %mmm to %dd %mm without writing some huge if statement in a transformer to convert the month?

Cheers,
Barry
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

You have to convert %mm%dd (mmdd - string). Other way it will be wrong results.
bmsq wrote:...the conversion from %dd %mmm to %dd %mm..
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

Try StringToDate function
Ex:
StringToDate('Mar 02 2003',"%mmm %dd %yyyy")
Will give you - "2003-03-02"

For the year part you can append a dummy year to your InDate field.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
bmsq
Premium Member
Premium Member
Posts: 32
Joined: Mon Oct 30, 2006 9:19 pm

Post by bmsq »

Josh,

When using a dummy year, do I need to ensure that I choose a leap year to ensure that "29 Feb" is valid?

Thanks,
Barry
JoshGeorge
Participant
Posts: 612
Joined: Thu May 03, 2007 4:59 am
Location: Melbourne

Post by JoshGeorge »

Missed that point. You have to use a leap year to ensure "29 Feb" is valid.
Joshy George
<a href="http://www.linkedin.com/in/joshygeorge1" ><img src="http://www.linkedin.com/img/webpromo/bt ... _80x15.gif" width="80" height="15" border="0"></a>
Post Reply