cancel
Showing results for 
Search instead for 
Did you mean: 

problem in UDF

former_member207622
Contributor
0 Kudos

Hi folks

I have a requirement in which i get the current date in yyyyy/mm/dd format and I have change it in yyyymmm format where mmm corresponds to 001------- 012

the logic is :

say i get 2009/05/04 then i have to pass -


> 2009004 the month should be reduced by 1 and 0 after 2009 is constant.

In case if the date is 2010/01/04 -


> i will have to pass 2009012 ... year is reduced by 1 and jan month is made as december .

How to achieve this ??

please reply!

thnx Ninad

Accepted Solutions (0)

Answers (4)

Answers (4)

prasannakrishna_mynam
Contributor
0 Kudos

Hi Ninad,

You need to use the UDF for this of type simple. And the code is as follows.

int mon=Integer.parseInt(a.substring(5,7));
int year=Integer.parseInt(a.substring(0,4));
if(mon==1){
   year--;
   mon=12;
			
}else{
  mon--;
}

String monStr= mon+"";
if(monStr.length()<2){
     return year+"00"+mon;
}else{
 return year+"0"+mon;	 
}		

It will work, All The Best.

Regards,

Prasanna

Former Member
0 Kudos

Hi..

Well basically you need an UDF. To extract the month, year.

You can find on this link.

http://www.java-examples.com/add-or-substract-days-current-date-using-java-calendar

Regards.

former_member181962
Active Contributor
0 Kudos

You can make use of Java date functions to achieve this.

Search sun.java.com for "previous month" or something like that..

Regards,

Ravi Kanth Talagana

MichalKrawczyk
Active Contributor
0 Kudos

hi,

you will need to write an UDF yourself as there

are no standard functions that handle adding month, etc.

but there are many examples on the net so just open google

and do a little search:

http://www.kodejava.org/examples/24.html

http://www.java-tips.org/java-se-tips/java.util/add-substract-day-month-year-to-a-date-15.html

Regards,

Michal Krawczyk