cancel
Showing results for 
Search instead for 
Did you mean: 

DatePicker - Wrong conversion in the date range - ToDate is increased by 1 day always

former_member184739
Contributor
3,600

Hello Experts,

I'm experiencing a weird scenario where the date range in the UI5 datepicker is not picking up the correct values. Let me summarize the steps done and what exactly the issue am facing.

I have placed the datepicker range as per the following code in the view.xml file.

<DateRangeSelection id="dateCreatedOn" placeholder="{i18n>enterCreatedOn} ..." valueFormat="MM-dd-yyyy" displayFormat="MM.dd.yyyy"/>

Date range selected in the user screen is captured in the controller.js as shown below.

if (dateCreatedOnFrom && dateCreatedOnTo) {
  dateCreatedOnFrom = new Date(dateCreatedOnFrom);
  dateCreatedOnTo = new Date(dateCreatedOnTo);
 this.inputFilters.push(new Filter("CreatedOn", FilterOperator.BT, dateCreatedOnFrom, dateCreatedOnTo));
			}

As you can notice when debugging this in Chrome, date range values i.e., both from and to are fine.

Date ranges selected in the UI5 application:

Values in Google Chrome console:

But when the odata call is triggered to SAP Gateway 'dateCreatedOnTo' value is changed i.e., increased by 1 day when the odata call is triggered.

/SearchResultSet?sap-client=110&$filter=CreatedBy eq 'SUZIP' and (CreatedOn ge datetime'2020-09-21T04:00:00' and CreatedOn le datetime'2020-09-25T03:59:59.999')

When call reached the backend i.e., ECC, we can notice the changed date values which leads to pull wrong data.

Note:

SAPUI5 version: 1.71.4 is deployed in the Gateway FrontEnd server.

Please shed some lights on this issue. Thank you for the support.

Regards

Praba

View Entire Topic
sergei-u-niq
Active Contributor

Note: The control is not UTC aware and the selected date range starts from 00:00:00:000 of the first date and ends in 23:59:59:999 on the second date.

(DateRangeSelection Docs)

you will need to adjust the From/To Date objects by the timezone shift, so they represent "picked date at 00:00:00 UTC"

the dateTo you picked is 23:59:59 your time zone, and gets correctly translated to the next day 3:59:59 UTC before submitting.

the date From you picked is 00:00:00 your time zone, and gets correctly translated to same day 4:00:00 (so you dont care)

in a different time zone, the opposite may happen : fromDate converted to 23:00:00 previous day