cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to convert into datetime format for oracle database

former_member207622
Contributor
0 Kudos

HI Folks

I need a UDF which will insert the date in datetimeformat in oracle database via jdbc 

my input is  say -    20120309 ( datab coming from idoc )  concatenated with constant ( 12.00.00 )

my input to udf will be 20120309 12.00.00  and my output should be  09-MAR-12 12.00.00

please help me at the earliest i tried date trans function but not working

Thanks

Ninad

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Ninad.

In DT add attribute hasQuot with default value "No", this for your field DATE

like this:

and also you must apply this function:

TO_DATE('15-02-2009 12:00:00 AM', 'dd-mm-yyyy HH:MI:SS AM') to field "DATE"

I hope help you.

Answers (6)

Answers (6)

Former Member
0 Kudos
deepak_shah
Contributor
0 Kudos

Hi Ninad,

check this link. this could be achieved using mapping itself. UDF is not required.

http://www.saptechnical.com/Tips/XI/Date/Oracle.htm

-Deepak

0 Kudos

Hi Ninad,

You can try this code -

make sure you import following in the import tab of udf -

java.text.SimpleDateFormat

java.uti.Date ;

sample code -

public String concatDate(String dateIdoc, String time, Container container) throws StreamTransformationException{

String oraDate = "" ;

Date date ;

SimpleDateFormat sdfSource  = new SimpleDateFormat("yyyyMMdd");

SimpleDateFormat sdfDestination = new SimpleDateFormat("dd-MMM-yyyy");

try {

date =  sdfSource.parse(dateIdoc);

}catch (Exception e)

{

     // your exception logic

}

oraDate= sdfDestination.format(date);

oraDate= oraDate+ " " +time ; //String time can be constant as per your requirement or if you get it from idoc you can use it as input to udf

return oraDate;

}

- Piyusha Deshpande

Former Member
0 Kudos

Dear Ninad

Date trans should work.

Input should be yyyyMMdd hh.mm.ss 

Output dd-MMM-yy hh.mm.ss

Regards

Monika

former_member184681
Active Contributor
0 Kudos

Hi Ninad,

There are few nice formatting examples here:
http://www.exampledepot.com/egs/java.text/formatdate.html

Try the following code in a UDF (assuming that your input parameter is called input😞
Format formatter;
Date date = DateFormat.parse(input);
formatter = new SimpleDateFormat("yy-MMM-dd HH.mm.ss");
String s = formatter.format(date);
return s;

Hope this helps,
Greg

Former Member
0 Kudos

try this: use datetrans method. input datab to it. double click it - set both input and output date formats. MMM shall give MAR for example. this will output date in req format.

then take time and concatenate it.