<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: Filter Date in a model with String using DatePicker in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/filter-date-in-a-model-with-string-using-datepicker/qaa-p/12649351#M4745393</link>
    <description>&lt;P&gt;This is my solution&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FilterTokens.forEach((token) =&amp;gt; {&lt;BR /&gt;            aFilters.push(&lt;BR /&gt;              new Filter({&lt;BR /&gt;                path: 'to_DocumentItems',&lt;BR /&gt;                operator: 'Any',&lt;BR /&gt;                variable: 'item',&lt;BR /&gt;                condition: new Filter({&lt;BR /&gt;                  path: 'item/ProductId_ProductId',&lt;BR /&gt;                  operator: "EQ",&lt;BR /&gt;                  value1: token.getKey(),&lt;BR /&gt;                })&lt;BR /&gt;              })&lt;BR /&gt;            );&lt;BR /&gt;          });&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Nov 2022 11:15:04 GMT</pubDate>
    <dc:creator>former_member824324</dc:creator>
    <dc:date>2022-11-29T11:15:04Z</dc:date>
    <item>
      <title>Filter Date in a model with String using DatePicker</title>
      <link>https://community.sap.com/t5/technology-q-a/filter-date-in-a-model-with-string-using-datepicker/qaq-p/12649350</link>
      <description>&lt;P&gt;Hello experts, I have a problem that I don't know how to solve:&lt;/P&gt;
  &lt;P&gt;I'm developing an application in which documents are filtered based on the date entered in the DatePicker. The problem is that in the db schema "DocumentDate" is of type string, and this type cannot be changed (in the db); I would then need to take the date, convert it to type Date and then apply the filter.&lt;/P&gt;
  &lt;P&gt;Surely something escapes me, but I do not know how I should do exactly. Below is the code.&lt;/P&gt;
  &lt;P&gt;Thanks everyone for your time.&lt;/P&gt;
  &lt;P&gt;Controller.js&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;        ///DatePicker//// 
        var dateFrom = this.dateFromFilter.getDateValue();
        var dateTo = this.dateToFilter.getDateValue();
        var PathValue = "DocumentDate";
        

        if (dateFrom &amp;amp;&amp;amp; dateTo) {
          
          console.log("BT");
          aFilters.push(new sap.ui.model.Filter({
            path: PathValue,
            test: function(oValue)
            {
              oValue=new Date(oValue);
              return (dateFrom&amp;lt;=oValue &amp;amp;&amp;amp; oValue&amp;lt;=dateTo)
            }
          }));
        } else if (dateFrom) {
          console.log("GE");
          aFilters.push(new sap.ui.model.Filter({
            path: PathValue,
            test: function(oValue)
            {
              oValue=new Date(oValue);
              return dateFrom&amp;lt;=oValue;
            }
          }));
        } else if (dateTo) {
          console.log("LE");
          aFilters.push(new sap.ui.model.Filter({
            path: PathValue,
            test: function(oValue)
            {
              oValue=new Date(oValue)
              return oValue&amp;lt;=dateTo;
            }
          }));
        }

        oTable.getBinding("items").filter(aFilters);&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;BR /&gt; 
  &lt;P&gt;.xml&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;&amp;lt;DatePicker id="DatePicker_Start" 
	displayFormat="short" 
	class="multiInputMaxWidth"/&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;DocumentHeader.csv&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;DOCUMENTID;STATUS;TOTALVALUE;CURRENCY;TOTALQUANTITY;DOCUMENTDATE;CUSTOMERORDER;REQUESTDELIVERYDATE;EFFECTIVEDELIVERYDATE;DELIVERYSTATUS;DELIVERYBLOCK;INVOICEBLOCK;PAYCONDITIONS;CustomerId_CustomerId;ShipToPartnerId_CustomerId
0000000001;STATUS9518;9649.76;CURRENCY7984;4510.45;01/01/2000;CUSTOMERORDER4967;REQUESTDELIVERYDATE2700;EFFECTIVEDELIVERYDATE4377;DELIVERYSTATUS3174;DELIVERYBLOC9207;INCOICEBLOC7690;PAYCONDITIONS8851;0000000001;0000000003
0000000002;STATUS2036;6191.53;CURRENCY8515;3169.44;01/01/2010;CUSTOMERORDER8183;REQUESTDELIVERYDATE7473;EFFECTIVEDELIVERYDATE3749;DELIVERYSTATUS4674;DELIVERYBLOC6190;INCOICEBLOC121;PAYCONDITIONS5183;0000000002;0000000002
0000000003;STATUS9479;9783.38;CURRENCY3920;1446.79;01/01/1990;CUSTOMERORDER2476;REQUESTDELIVERYDATE3081;EFFECTIVEDELIVERYDATE129;DELIVERYSTATUS3606;DELIVERYBLOC5509;INCOICEBLOC2220;PAYCONDITIONS1751;0000000002;0000000004&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Schema.cds&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;entity DocumentHeader
{
    key DocumentId : String(100)
        @Core.Computed;
    Status : String(100);
    TotalValue : Double;
    Currency : String(100);
    TotalQuantity : Double;
    DocumentDate : String(100);
    CustomerOrder : String(100);
    RequestDeliveryDate : String(100);
    EffectiveDeliveryDate : String(100);
    DeliveryStatus : String(100);
    DeliveryBlock : String(100);
    InvoiceBlock : String(100);
    PayConditions : String(100);
    CustomerId : Association to one Customer;
    ShipToPartnerId : Association to one Customer;
    to_DocumentItems : Association to many DocumentItem on to_DocumentItems.DocumentId = $self;
    to_PriceConditions : Association to many PriceCondition on to_PriceConditions.DocumentId = $self;
    to_Partners : Association to many Partner on to_Partners.DocumentId = $self;
    to_Notes : Association to many Note on to_Notes.DocumentId = $self;
}&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;Some screen:&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2113675-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2113677-image.png" /&gt;&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/2113676-image.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2022 11:47:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/filter-date-in-a-model-with-string-using-datepicker/qaq-p/12649350</guid>
      <dc:creator>former_member824324</dc:creator>
      <dc:date>2022-11-23T11:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Date in a model with String using DatePicker</title>
      <link>https://community.sap.com/t5/technology-q-a/filter-date-in-a-model-with-string-using-datepicker/qaa-p/12649351#M4745393</link>
      <description>&lt;P&gt;This is my solution&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;FilterTokens.forEach((token) =&amp;gt; {&lt;BR /&gt;            aFilters.push(&lt;BR /&gt;              new Filter({&lt;BR /&gt;                path: 'to_DocumentItems',&lt;BR /&gt;                operator: 'Any',&lt;BR /&gt;                variable: 'item',&lt;BR /&gt;                condition: new Filter({&lt;BR /&gt;                  path: 'item/ProductId_ProductId',&lt;BR /&gt;                  operator: "EQ",&lt;BR /&gt;                  value1: token.getKey(),&lt;BR /&gt;                })&lt;BR /&gt;              })&lt;BR /&gt;            );&lt;BR /&gt;          });&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2022 11:15:04 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/filter-date-in-a-model-with-string-using-datepicker/qaa-p/12649351#M4745393</guid>
      <dc:creator>former_member824324</dc:creator>
      <dc:date>2022-11-29T11:15:04Z</dc:date>
    </item>
  </channel>
</rss>

