Page 1 of 1

How to Convert Dates

Posted: Mon Jul 15, 2013 5:01 am
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...

Posted: Mon Jul 15, 2013 5:27 am
by jerome_rajan
I think OCONV requires the argument in the internal format as generated by ICONV.

How to convert dates

Posted: Mon Jul 15, 2013 6:22 am
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

Posted: Mon Jul 15, 2013 7:38 am
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.

Posted: Mon Jul 15, 2013 7:58 am
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...

Posted: Mon Jul 15, 2013 4:49 pm
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.