Skip to Content
Author's profile photo Victoria sangula

How to count the selected days excluding week days in a calendar in SAP UI5

Hi All,

As i am a fresher to sapui5, i’ve been learning sapui5 and i have a task about calendars.

I have gone through SDK demokit and learnt some points , i will be keeping those points here.

In this blog i want to explain about “how to count the selected days excluding week days in a calendar”.

Step 1: First we need to create a Project in SAP Web IDE , here i am creating a project with the name of “Exsatsun” which is shown below.

Step 2: In the View, i have wrote code to display “Calendar” using “sap.ui.unified”.


<mvc:View controllerName="Exsatsun.controller.View1" xmlns:html="" xmlns:mvc="sap.ui.core.mvc"
	xmlns:u="sap.ui.unified" xmlns:core="sap.ui.core" xmlns="sap.m">
			<Page title="{i18n>title}">
					<u:Calendar id="Cal1" select="handleCalendarSelect" intervalSelection="true"/>


After writing the above code and execution the view will be like as

Now write the controller code for “handleCalendarSelect” to display number of selected days excluding week days.


	handleCalendarSelect: function() {
			var oCalender = this.getView().byId("Cal1");
			oCalender = this.getView().byId("Cal1");
			var aSelectedDates = oCalender.getSelectedDates();
			var oStartDate = aSelectedDates[0].getStartDate();
			var oEndDate = aSelectedDates[0].getEndDate();
			var count = 0;
			while (oStartDate <= oEndDate) {
				if (oStartDate.getDay() !== 0 && oStartDate.getDay() !== 6)
				oStartDate.setDate(oStartDate.getDate() + 1);
			} + "" + "days selected");

After writing the above controller code and execution, the output will be:


Select Start date and end date from the calendar, if there are any week days (Saturday and Sunday) the count will be decreased by two days.

Here i have selected 9 days with week days but the output shows 7 days, means it excluded the week days.

Hope useful for beginners 🙂


Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Matthew Billingham
      Matthew Billingham

      Now link it to a back-end factory calendar in ERP, so that it can count only working days.