on 04-15-2009 3:31 PM
Dear All,
I am having two variables in which one is having value as "20090415" and other is having value as "5". I need to get the output by subtracting the two variables as "20090410". Also, we need to take care if month is getting changed eg "20090501" - "2" = "20090429".
Please help me in creating UDF for the same.
Regards,
NJ
Hi Jain,
Create a value user defined function SubtractDays and take two input values BaseDate and Days.
Import: java.text.*;java.util.Date;java.util.Calendar;java.util.GregorianCalendar;
Add this code:
//write your code here
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date d = null;
try {d = sdf.parse(BaseDate);} catch (ParseException e) {}
GregorianCalendar gc = new GregorianCalendar();
gc.setTime(d);
gc.add(Calendar.DATE, Integer.parseInt(Days));
Date end = gc.getTime();
return sdf.format(end);
The first input for this udf should be your date. For the second input you need to send the no. of days, but here you concatenate with '-' so that if you send the input as 2 it goes as -2 as an second input to the udf. Then it should work for you.
Regards,
---Satish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
there are soo many pages which show how to do that:
http://www.java-tips.org/java-se-tips/java.util/add-substract-day-month-year-to-a-date.html
http://www.kodejava.org/examples/24.html
just have a look at them and you're done with this issue
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 |
---|---|
76 | |
9 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.