on 11-28-2007 7:14 AM
hello
i have a from date and to date field
i have to set the to date as (current date) default
and the from date to (current date - 7 days) default
how do i code for this in webdynpro java.
Hi rohan,
In poojith's reply he is subtracting 72460*60 to get to 7 days old date.
For one month, replace 7 by 30 and for 1 year replace 7 by 365.
java.sql.date dtToDate = new Date(System.currentTimeMillis());
java.sql.date dtTempDate = dtToDate - (72460*60);// 7 days before
java.sql.date dtTempDate = dtToDate - (302460*60);// 1 month before
java.sql.date dtTempDate = dtToDate - (3652460*60);// 1 year before
java.sql.date dtFromDate = new Date(dtTempDate);
Best regards,
Sangeeta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hello again
now if
my to date is the current date
and the from date should be (current date - 1 month)
or (current date - 1 year) default
how should i code for this...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Example for current date - 1 day (1 month, 1 year etc should be the very similar...)
Calendar cal = Calendar.getInstance(); // today
cal.add(Calendar.DAY_OF_YEAR, -1);
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
wdComponentAPI.getMessageManager().reportSuccess(sdf.format(cal.getTime()));
Regards,
Omri
Hi Rohan,
Try the following piece of code :-
<b>java.sql.date dtToDate = new Date(System.currentTimeMillis());
java.sql.date dtTempDate = dtToDate - (72460*60);
java.sql.date dtFromDate = new Date(dtTempDate);</b>
hope this helps u.
Regards,
Poojith MV
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rohan
java.util.Date monday = DateHelper.getMondayDateOfCurrentWeek();
// it will get the monday of the current week
java.util.Date sunday = DateHelper.addDays(monday, 6);
//it will get the sunday of the current week (in this context Monday is firstday and sunday is the last day)
Date fromDate = new Date(monday.getTime());
Date toDate = new Date(sunday.getTime());
wdContext.currentContextElement().setFromDate(fromDate);
//Sets the monday to your input field (Date Picker)
wdContext.currentContextElement().setToDate(toDate);
//Sets the sunday to your input field (Date Picker)
create a java project and add this code to that project
code for getMondayDateofCurrentWeek and addDays is as follows..please refer to this and make changes accordingly
actually this is a java file .which i included in my project . DateHelper is my class name.you also do the same and .class file to your webdynpro project
static public Date getMondayDateOfCurrentWeek() {
Date today = new Date();
Date monDate = today;
int day = getDayOfWeek(today);
//2 because 2 is Monday
if (day > 2)
{
while (day > 2)
{
monDate = yesterday(monDate);
day = getDayOfWeek(monDate);
}
}
else
{
while (day < 2)
{
monDate = tomorrow(monDate);
day = getDayOfWeek(monDate);
}
}
return monDate;
}
static public final Date addDays(Date target, int days)
{
// returns a Date that is the sum of the target Date
// and the specified number of days;
// to subtract days from the target Date, the days
// argument should be negative
long msPerDay = 1000 * 60 * 60 * 24;
long msTarget = target.getTime();
long msSum = msTarget + (msPerDay * days);
Date result = new Date();
result.setTime(msSum);
return result;
}
For More reference <a href="https://forums.sdn.sap.com/click.jspa?searchID=6993015&messageID=4032225">Look this thread</a>
Best Regards
Chaitanya.A
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.