简体   繁体   English

使用sapui5的日期过滤器

[英]Date filter using sapui5

I want to use filter with date , the filter should be somthing like that : 我想使用带日期的过滤器,过滤器应该像这样:

/MyEntitySet?$filter=Erdat gt datetime'2018-02-04T00:00:00' and Erdat lt 
datetime'2018-02-04T00:00:00

But I don't get that while using this in sapui5 : 但是在sapui5中使用它时我没有得到:

var date = this.byId("date1").getDateValue();
var date2 = this.byId("date2").getValue();
var oDateFormat = sap.ui.core.format.DateFormat.getInstance({
  pattern: "yyyy-MM-ddTHH:mm:ss"
});
var oDate = oDateFormat.format(oDateFormat.parse(date));

var oDateFormat2 = sap.ui.core.format.DateFormat.getInstance({
  pattern: 'yyyy-MM-ddTHH:MM:SS'
});
var oDate2 = oDateFormat.format(oDateFormat.parse(date2));

Anyone have an idea about that please , I will be grateful. 任何人对此都有一个想法,我将不胜感激。 Thank you 谢谢

You don't need to format the data by yourself, just build the Filter and apply to the odata request directly. 您不需要自己格式化数据,只需构建过滤器并直接应用于odata请求即可。

sap.ui.define(['sap/ui/model/Filter', 'sap/ui/model/FilterOperator'], 
  function(Filter, FilterOperator) {
    new Filter({
      path: "Erdat",
      operator: FilterOperator.BT,
      value1: date,
      value2: date2
    });
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM