ChangeTimestamptoyear

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
kumar_j
Participant
Posts: 45
Joined: Mon Nov 28, 2005 2:43 am

ChangeTimestamptoyear

Post by kumar_j »

hi all,
I Want to convert my timestamp to month and year in separate columns. From which function i have to extract

thanks
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

What format is your timestamp in?
Take a look at the ICONV/OCONV functions.
If your date part of timestamp is alway YYYY-MM-DD
then for year you can do

Code: Select all

LEFT(in.timestamp,4)
for month you can do

Code: Select all


OCONV(ICONV(LEFT(in.timestamp,10),"D-YMD[4,2,2]"),"DM")
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

If your 'timestamp' comes in in a consistent format, both pieces can simply be sub-stringed out.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kumar_j
Participant
Posts: 45
Joined: Mon Nov 28, 2005 2:43 am

HI SDguru2B

Post by kumar_j »

MY DATE format is in YYYY-MM-DD
I got the month ,how to get the year part like the one u provided for month
thks in advance
DSguru2B wrote:What format is your timestamp in?
Take a look at the ICONV/OCONV functions.
If your date part of timestamp is alway YYYY-MM-DD
then for year you can do

Code: Select all

LEFT(in.timestamp,4)
for month you can do

Code: Select all


OCONV(ICONV(LEFT(in.timestamp,10),"D-YMD[4,2,2]"),"DM")
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Pay attention to Craig's suggestion. That will be much faster.
As far as getting the year from ICONV/OCONV, use

Code: Select all

OCONV(ICONV(LEFT(in.timestamp,10),"D-YMD[4,2,2]"),"DY") 
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
rwierdsm
Premium Member
Premium Member
Posts: 209
Joined: Fri Jan 09, 2004 1:14 pm
Location: Toronto, Canada
Contact:

Re: HI SDguru2B

Post by rwierdsm »

Kumar,

Assuming format YYYY-MM-DD, Craig's suggestion breaks down to

Year = in.timestamp [1, 4]
Month = in.timestamp [6, 2]

Are you looking for more than that?

Rob
Rob Wierdsma
Toronto, Canada
bartonbishop.com
kumar_j
Participant
Posts: 45
Joined: Mon Nov 28, 2005 2:43 am

THKS

Post by kumar_j »

Thnks all,
i got the answer
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If month might be one or two digits, the Field() function is more appropriate.

Code: Select all

Field(in.Timestamp, "-", 2, 1)
Adapt as required for different delimiter character.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply