on 08-30-2007 3:46 AM
Hi,
I need to set the first day on a week to Monday for a UI InputField ( datepicker), but so far I have not have any luck.
I have managed to add a UI InputField to the layout and assigned it to a context variable of type Date.
Im on NW04s SP11.
Please help!
Best regards,
Henrik
Hi Henrik
code for <b>getMondayDateofCurrentWeek and addDays</b> 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;
}
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.
Hi
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)
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 |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.