on 2020 Sep 24 9:23 PM
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
Request clarification before answering.
Hi Folks,
Below code snippet was added to send the correct date to SAP backend after formatting. I hope this helps.
var dateCreatedOnFrom = oView.byId("dateCreatedOn").getDateValue().
var dateCreatedOnTo = oView.byId("dateCreatedOn").getSecondDateValue().
if (dateCreatedOnFrom && dateCreatedOnTo) {
//Format date to remove UTC issue
var oFormatDate = sap.ui.core.format.DateFormat.getDateTimeInstance({
pattern: "yyyy-MM-ddTKK:mm:ss"
});
//Convert DateTime into Date to avoid TimeZone Issue
var oDateFrom = oFormatDate.format(dateCreatedOnFrom);
oDateFrom = oDateFrom.split("T");
dateCreatedOnFrom = oDateFrom[0];
var oDateTo = oFormatDate.format(dateCreatedOnTo);
oDateTo = oDateTo.split("T");
dateCreatedOnTo = oDateTo[0];
this.inputFilters.push(new Filter("CreatedOn", FilterOperator.BT, dateCreatedOnFrom, dateCreatedOnTo));
}
Regards
Praba
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
maybe a small improvement to your code:
new Date( dateCreatedOnFrom.getTime() - dateCreatedOnFrom.getTimezoneOffset() * 60 * 1000 )
(this way you don't need to work with formatters or rely on string representations - just work with the date object)
User | Count |
---|---|
89 | |
11 | |
9 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.