on 05-19-2009 2:25 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.