How to get the correct "CENTURY" if from 2-digit Y

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
UPS
Premium Member
Premium Member
Posts: 56
Joined: Tue Oct 10, 2006 12:18 pm
Location: New Jersey

How to get the correct "CENTURY" if from 2-digit Y

Post by UPS »

If my date is 03-JAN-07 and I'd like to format it to be YYYY-MMM-DD, is there a way in Datastage for it to automatically put "20" in front of "07" for the year?

My current workaround for this is I do an if-then-else derivation similar to the following:
If datevar[8,2] > 50 then '19' else '20'

Is this another way to get the century???
Bhavesh.Shah
Participant
Posts: 4
Joined: Fri May 25, 2007 9:20 am

Post by Bhavesh.Shah »

If you can afford a Basic Transformer in your Parallel Job then a combination of Iconv & Oconv can get you the desired results.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why not just StringToDate() with the proper mask?
-craig

"You can never have too many knives" -- Logan Nine Fingers
UPS
Premium Member
Premium Member
Posts: 56
Joined: Tue Oct 10, 2006 12:18 pm
Location: New Jersey

Post by UPS »

I used StringToTimestamp function and was using 'yyyy' for the year for masking. However, for 2-digit '07' as the year, it was populating it with 19 --> so the result was 1907, instead of 2007. What is the proper mask to put the correct century? The on-line documents do not have examples.

Any input is greatly appreciated.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Not sure why you get 1907 rather than 2007, but here's what is in the docs:
For a date, the format components are:
%dd two digit day
%mm two digit month
%yy two digit year (from 1900)
%year_cutoffyy two digit year from year_cutoff (e.g. %2000yy)
%yyyy four digit year
%ddd three digit day of the year
The default format is %yyyy-%mm-%dd
Try the 'year_cutoff' version.
-craig

"You can never have too many knives" -- Logan Nine Fingers
UPS
Premium Member
Premium Member
Posts: 56
Joined: Tue Oct 10, 2006 12:18 pm
Location: New Jersey

Post by UPS »

Thank you! The year_cutoffyy will work! Thanks for your quick reply.
sribuz
Premium Member
Premium Member
Posts: 19
Joined: Mon Jun 04, 2007 7:26 pm
Location: US

yearcut off works

Post by sribuz »

Thanks craig, I was having same problem with timestamp and after looking at your reply used %2000yy instead of %yy and got the correct output.
Thanks & Regards,
Sri
Post Reply