<?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: How to query dates using &amp;quot;between&amp;quot; parameter ? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/how-to-query-dates-using-quot-between-quot-parameter/qaa-p/12462908#M4668300</link>
    <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;senz.evo&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;It looks like there is a logic issue in your query to match the condition above.&lt;/P&gt;&lt;P&gt;In the parameters, you are looking for a "from date" that MUST be between the "from date" and "to date" of your record and the same logic applies to the "to date".&lt;/P&gt;&lt;P&gt;For the pay period "JAN2020D1", the first query parameter will find the record, as the "from date" is between the two dates in "JAN2020". However, the "to date" of the second record is not between the two dates of the first one.&lt;/P&gt;&lt;P&gt;If I correctly understood the condition that should be tested, my guess is to keep only the first parameter "from date", that should be between the dates of your first record.&lt;/P&gt;&lt;P&gt;That should resolve your problem!&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jun 2021 17:18:26 GMT</pubDate>
    <dc:creator>former_member665936</dc:creator>
    <dc:date>2021-06-08T17:18:26Z</dc:date>
    <item>
      <title>How to query dates using "between" parameter ?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-query-dates-using-quot-between-quot-parameter/qaq-p/12462907</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;
  &lt;P&gt;I need to set validation for the below condition.&lt;/P&gt;
  &lt;P&gt;Condition : If user try to enter a From Date/ To Date between the existing From date and To date, it should through error.&lt;/P&gt;
  &lt;P&gt;Here in the example image the second record is invalid as its From Date falls between First Row's From and To.&lt;/P&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1945596-njaxl.png" /&gt;&lt;/P&gt;
  &lt;P&gt;I tried the below code:&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;	var queryPP = CBO_PayPeriod.QueryByElements;
	var queryPP_SelParams = queryPP.CreateSelectionParams();

	queryPP_SelParams.Add(queryPP.FromDate, "I", "BT", this.FromDate, this.ToDate );//, this.ToDate);
	queryPP_SelParams.Add(queryPP.ToDate, "I", "BT", this.FromDate, this.ToDate );//, this.ToDate);

	var queryPP_Results = queryPP.ExecuteFromDBDataOnly(queryPP_SelParams);


	if (queryPP_Results.Count() &amp;gt; 1)
	{
		raise Msg.Create("E", "Payperiod already available for the selected from and to date");
		return false;
	}
&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1945595-ytvrn.png" /&gt;&lt;/P&gt;
  &lt;P&gt;But my &lt;STRONG&gt;query doesn't return any record&lt;/STRONG&gt;, so the validation fails. Could anyone point what could be issue ?&lt;/P&gt;
  &lt;P&gt;Thanks,&lt;/P&gt;
  &lt;P&gt;Senz&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 16:03:44 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-query-dates-using-quot-between-quot-parameter/qaq-p/12462907</guid>
      <dc:creator>former_member187312</dc:creator>
      <dc:date>2021-06-08T16:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to query dates using "between" parameter ?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-query-dates-using-quot-between-quot-parameter/qaa-p/12462908#M4668300</link>
      <description>&lt;P&gt;Hi &lt;SPAN class="mention-scrubbed"&gt;senz.evo&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;It looks like there is a logic issue in your query to match the condition above.&lt;/P&gt;&lt;P&gt;In the parameters, you are looking for a "from date" that MUST be between the "from date" and "to date" of your record and the same logic applies to the "to date".&lt;/P&gt;&lt;P&gt;For the pay period "JAN2020D1", the first query parameter will find the record, as the "from date" is between the two dates in "JAN2020". However, the "to date" of the second record is not between the two dates of the first one.&lt;/P&gt;&lt;P&gt;If I correctly understood the condition that should be tested, my guess is to keep only the first parameter "from date", that should be between the dates of your first record.&lt;/P&gt;&lt;P&gt;That should resolve your problem!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jun 2021 17:18:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-query-dates-using-quot-between-quot-parameter/qaa-p/12462908#M4668300</guid>
      <dc:creator>former_member665936</dc:creator>
      <dc:date>2021-06-08T17:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to query dates using "between" parameter ?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-to-query-dates-using-quot-between-quot-parameter/qaa-p/12462909#M4668301</link>
      <description>&lt;P&gt;Hi  &lt;SPAN class="mention-scrubbed"&gt;matheus.wurth&lt;/SPAN&gt;,&lt;/P&gt;&lt;P&gt;Sorry, I missed a detail in my question. I have two cases in my query, below image would explain better.&lt;/P&gt;&lt;P&gt;&lt;IMG class="migrated-image" src="https://community.sap.com/legacyfs/online/storage/attachments/storage/7/attachments/1945605-timeframe-query.png" /&gt;&lt;/P&gt;&lt;P&gt;Here I'm expecting the query should consider both the cases.&lt;/P&gt;&lt;P&gt;One way I could think of is like first check only From date that falls between an existing record's date and throw error then clear parameter and repeat the same for To Date.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;	var queryPP = CBO_PayPeriod.QueryByElements;
	var queryPP_SelParams = queryPP.CreateSelectionParams();

	queryPP_SelParams.Add(queryPP.FromDate,"I", "BT", this.FromDate, this.ToDate );

	var queryPP_Results = queryPP.ExecuteFromDBDataOnly(queryPP_SelParams);

        if(queryPP_Results.Count()&amp;gt; 0)
        {
           raise Msg.Create("E", "Payperiod already available for the selected from and to date");
           return false;
        }

        queryPP_SelParams.Clear();

	queryPP_SelParams.Add(queryPP.ToDate,"I", "BT", this.FromDate, this.ToDate );

	var queryPP_Results = queryPP.ExecuteFromDBDataOnly(queryPP_SelParams);

        if(queryPP_Results.Count()&amp;gt; 0)
        {
           raise Msg.Create("E", "Payperiod already available for the selected from and to date");
           return false;
        }

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But its not an optimized one. Anyways to combine both the logic into single query execution?&lt;/P&gt;&lt;P&gt;BR,&lt;/P&gt;&lt;P&gt;Senz&lt;/P&gt;</description>
      <pubDate>Wed, 09 Jun 2021 05:23:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-to-query-dates-using-quot-between-quot-parameter/qaa-p/12462909#M4668301</guid>
      <dc:creator>former_member187312</dc:creator>
      <dc:date>2021-06-09T05:23:29Z</dc:date>
    </item>
  </channel>
</rss>

