cancel
Showing results for 
Search instead for 
Did you mean: 

How to set firstDayOfWeek on a UI InputField

HenrikD
Participant
0 Kudos

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.

I’m on NW04s SP11.

Please help!

Best regards,

Henrik

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

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

Former Member
0 Kudos

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

HenrikD
Participant
0 Kudos

Hi Chaitanya,

I think you have misunderstood me

I am not looking for ways to add dates to a context variable, but a way to get the first week day on the ‘datepicker’ of the UI InputField to be Monday. Default it is Sunday.

Have you any advice on how I can do that?

Best regards,

Henrik

Former Member
0 Kudos

Hi

Just clear me one thing.

1) are you using a <b>Date</b> Simple Type and binding that to an Input field or

2) are you using <b>Date Navigator</b> UI Element

Regards

Chaitanya.A

HenrikD
Participant
0 Kudos

Hi Chaitanya,

I go for 1. I have an input field which is assigned a context variable of type Date.

I know that the UI DataNavigator has a property firstDayOfWeek , but i need to get the ‘DatePicker’ for the UI InputField to show Monday as first week day.

Best regards,

Henrik

Former Member
0 Kudos

Hi Henrik

I tried this .it is showing me MONDAY as the first day of the week.

it will highlight today's date

Regards

Chaitanya.A

Former Member
0 Kudos

Hi Henrik

can you please explain me in detail..

Regards

Chaitanya.A