How to Convert Dates

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
Rajendra_89
Participant
Posts: 22
Joined: Fri Jul 12, 2013 7:32 am

How to Convert Dates

Post by Rajendra_89 »

Hi All,

As the Built-in Date functions are not available in Server jobs (Like the YearFromDate(Input_date) iin Parallel jobs)

Can anybody help me to implement DateConversion in Server Edition?

I have tried using Oconv function as shown below

Oconv(Input_date, "D Y")

But this is not working... Am I missing anything here?

Is there any other method of Implementing Date and other conversions?
If Yes please share that also...
Rajendra
ETL Developer
InfoCepts
jerome_rajan
Premium Member
Premium Member
Posts: 376
Joined: Sat Jan 07, 2012 12:25 pm
Location: Piscataway

Post by jerome_rajan »

I think OCONV requires the argument in the internal format as generated by ICONV.
Jerome
Data Integration Consultant at AWS
Connect With Me On LinkedIn

Life is really simple, but we insist on making it complicated.
mf_arts
Participant
Posts: 21
Joined: Wed Oct 19, 2005 5:10 am
Location: Dublin

How to convert dates

Post by mf_arts »

Hi rajendra_89

You need to be more specific, what sort of converstion are you trying to achieve?
For example:
1- if you want to change from mm/dd/yyyy and the desired output is yyyy/mm/dd you may use the foolow:
Oconv(Iconv(DateAttribute,"DMDY"),"D/YMD[4,2,2]")

2 - If you want to add 2 days to the existing date and assuming input date is in the dd/mm/yyy format, you can do the follow:

Oconv(Iconv(InputFieldName,"DDMY") + 2,"D/DMY[2,2,4]")

Perhaps reading the "Server Job Developer's Guide" Chapter 7. BASIC Programming in page 239 will help.

regards,
Mario Fernandes
Mario Fernandes

An expert is one who knows more and more about less and less. - Nicholas Murray Butler
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Server is very forgiving and technically everything is a string under the covers. If you want the year from a date I would just substring out those 4 characters. Or use the Field() function.
jerome_rajan wrote:I think OCONV requires the argument in the internal format as generated by ICONV
Yes, it does require an internal date format but IConv is not the only way to get that. Most of the built-in current date macros / system variables return that format from what I recall. Of course and as noted, dates coming in from other sources would need to first need to be converted to internal format via IConv if you really need the services that OConv bring to the table.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Rajendra_89
Participant
Posts: 22
Joined: Fri Jul 12, 2013 7:32 am

Post by Rajendra_89 »

Thanks for your inputs Jerome

I think Mario has given the solution for the point you mentioned

Meanwhile while working on the problem I have come up with the two solutions

My Date is in the format YYYY-MM-DD and I want to convert it to the format in one of the requirement as only YYYY and in the other requirement as only MM

First Solution goes like this
1. Substrings( Oconv(Input_Date,"D"),6,2) --for Month
2. Substrings( Oconv(Input_Date,"D"),1,4) -- For YEAR

And the Second solution is by using the Transform Built-in Sdk function

1. DateYearFirstGetYear(Input_Date) -- (For YEAR)
2. DateYearFirstGetMonth(Input_Date) -- (For Month)

And With Marios Hint I have got the third solution as

1. Oconv(Iconv(Data_In.DATE,"D/YMD[4,2,2]"),"DM") --For Month
2.Oconv(Iconv(Data_In.DATE,"D/YMD[4,2,2]"),"DM") -- For Year

Thanks Mario for your inputs as welll

Further Mario ,I request you to please provide me the link for Server Job Developer's Guide which you mentioned... I tried to find the Developers guide for the Server jobs but couldn't find...
Rajendra
ETL Developer
InfoCepts
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

All manuals are available on your installation media, and may well have been installed on your client. Otherwise most manuals - and definitely the Server Job Developer's Guide - may be downloaded free from IBM. Just make sure you have the correct version.
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