on 03-03-2008 3:20 PM
Hello,
I have got two date fields in my webdynpro application. I am selecting one begin date from one field and an end date from another field and I need to calculate the middle date from these two. I will be calculating the year, month and quarter based on this middle date. I have written a code in which I am able to find difference in days between the two dates but am unable to get the same in date format. My code is:
long diff = wdContext.currentContextElement().getEnd_lc().getTime() - wdContext.currentContextElement().getBegin_date().getTime();
int daysdiff = (int)(diff /(1000*60*60*24*2))*2;
This code gives me the number of days. Please tell me how to complete my requirement.
Regards,
Gaurav
Hi Gaurav,
Use following code.
Date mdl=Date.valueOf("2008-01-01");//initialize the variable
long diff = wdContext.currentContextElement().getEnd_lc().getTime() - wdContext.currentContextElement().getBegin_date().getTime();
mdl.setTime(wdContext.currentContextElement().getBegin_date().getTime()+(diff/2));
This will set the middle date in variable mdl.
Regards
Deepak
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks a lot Deepak...
The code worked and Now aI am able to calculate the middle date.
Thanks again
Regards,
Gaurav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use the GregorianCalendar class or any other Calendar class reflecting the calendar you want to calculate with:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/GregorianCalendar.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
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.