<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.appian.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Query beetwen two dates</title><link>https://community.appian.com/discussions/f/data/20140/query-beetwen-two-dates</link><description>Hi, I kindly ask you for an opinion on a problem that I have been dragging along for some time. I have a query in which I need to extract data between two dates: startDate and endDate. The data on the db and CDT are in date and time format. The range</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: Query beetwen two dates</title><link>https://community.appian.com/thread/78729?ContentTypeID=1</link><pubDate>Wed, 30 Dec 2020 14:27:54 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:19b82526-e5ef-4341-b431-8979cf3ba734</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;A datetime stored in the DB is actually stored as a number that, as far as I remember, is accurate to the millisecond (and if that&amp;#39;s wrong, it&amp;#39;s at least accurate to the second).&amp;nbsp; Basically that means that when you want to query &amp;quot;everything for X date&amp;quot; for a column that stores a dateTime, it should always be sufficient to query between &amp;quot;Midnight of Date X&amp;quot; and &amp;quot;Midnight of Date X+1&amp;quot; (as opposed to bending over backwards to compare against &amp;quot;Date X at 23:59:59&amp;quot; specifically).&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query beetwen two dates</title><link>https://community.appian.com/thread/78728?ContentTypeID=1</link><pubDate>Wed, 30 Dec 2020 13:54:39 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:73fc5d94-dc39-4744-9fbe-224357649996</guid><dc:creator>Paolo Scolamacchia</dc:creator><description>&lt;p&gt;Hello Mike, &lt;br /&gt;I too have always done as you do!&lt;/p&gt;
&lt;p&gt;But could you please explain a little bit more what you meant by &amp;quot;since there&amp;#39;s not even a millisecond of overlap time when all is said and done&amp;quot; ?&lt;/p&gt;
&lt;p&gt;Thanks in advance, regards&lt;br /&gt;Paolo&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query beetwen two dates</title><link>https://community.appian.com/thread/78727?ContentTypeID=1</link><pubDate>Wed, 30 Dec 2020 13:53:17 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:d9c0be78-74d0-4ec8-b815-518fa57933b8</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;I don&amp;#39;t believe that&amp;#39;s likely given what I suggested above - quite literally what it will query is (&amp;quot;anything from the beginning of startDate&amp;quot;) until (&amp;quot;end of the day on endDate&amp;quot;).&amp;nbsp; The only possible extra adjustment that would be needed is ensuring your values are playing properly with GMT, and that&amp;#39;s pretty easy to test by adding some test entries to the DB with times very near midnight (some just before and some just after) to make sure they come up in the expected query.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query beetwen two dates</title><link>https://community.appian.com/thread/78715?ContentTypeID=1</link><pubDate>Wed, 30 Dec 2020 08:56:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:5e357e98-b5f5-4ba7-ab01-510c2df7193c</guid><dc:creator>Gabriele Minardi</dc:creator><description>&lt;p&gt;OK Mike, I also always used to add 1 day to the end date but in some cases it happened to lose a data that was instead included in the range or to add one that shouldn&amp;#39;t&amp;nbsp;have to appear after the query.&amp;nbsp;So I focused my attention on finding an alternative solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query beetwen two dates</title><link>https://community.appian.com/thread/78707?ContentTypeID=1</link><pubDate>Tue, 29 Dec 2020 13:54:04 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:0d765fa6-3598-4b68-a4e0-1bdd84de91ac</guid><dc:creator>Mike Schmitt</dc:creator><description>&lt;p&gt;what i&amp;#39;ve always done is just added 1 day to the end date (since there&amp;#39;s not even a millisecond of overlap time when all is said and done).&amp;nbsp; When querying from the database you need to be careful because I think Appian automatically does some conversion back from GMT when using a passed Appian date or dateTime object.&lt;/p&gt;
&lt;p&gt;i.e.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="java"&gt;value: {
  todatetime(ri!startDate),
  todatetime(ri!endDate + 1)
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query beetwen two dates</title><link>https://community.appian.com/thread/78698?ContentTypeID=1</link><pubDate>Tue, 29 Dec 2020 11:25:16 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:1cc46064-710d-4958-9437-c01f475eaeac</guid><dc:creator>Gabriele Minardi</dc:creator><description>&lt;p&gt;Hi Danny,&lt;/p&gt;
&lt;p&gt;taking into account your suggestion on using datetime() function, I think a better solution for me is using the following date filter:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;      
value:{          
    gmt(datetime(year(ri!startDate), month(ri!startDate), day(ri!startDate), 0, 0, 0 ) ) ,
    gmt(datetime(year(ri!endDate), month(ri!endDate), day(ri!endDate), 23, 59, 59 ) ) 
}    &lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This solution is valid if we assume that the writing of the dates is done by Appian because of the handling date and time.&lt;/p&gt;
&lt;p&gt;&lt;a href="/w/the-appian-playbook/983/handling-date-and-time"&gt;https://community.appian.com/w/the-appian-playbook/983/handling-date-and-time&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query beetwen two dates</title><link>https://community.appian.com/thread/78693?ContentTypeID=1</link><pubDate>Mon, 28 Dec 2020 16:06:49 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:daa54c76-962e-44a4-acac-b90662161d31</guid><dc:creator>Gabriele Minardi</dc:creator><description>&lt;p&gt;Thanks Danny,&lt;br /&gt;but I&amp;#39;m not sure I understand.&lt;br /&gt;The second queryFilter does not give errors but it seems to me too complicated.&lt;br /&gt;The point is that, taking for example the second extreme of the query,&lt;br /&gt;if the user enters e.g. Nov 15 2020,&lt;br /&gt;the query should have as endDate: Nov 15 2020 11:59 PM, to extract all data with timestamp of the day.&lt;br /&gt;but the simple todatetime (--15-Nov-2020--) returns&lt;br /&gt;15 Nov 2020 1:00 AM GMT+1&amp;nbsp; so all data after 1:00 AM will be excluded from the query.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Query beetwen two dates</title><link>https://community.appian.com/thread/78692?ContentTypeID=1</link><pubDate>Mon, 28 Dec 2020 15:04:09 GMT</pubDate><guid isPermaLink="false">d3a83456-d57b-489c-a84c-4e8267bb592a:fd09b3f3-f8c1-4fea-a642-75647e9d93f1</guid><dc:creator>Danny Verb</dc:creator><description>&lt;p&gt;You can&amp;#39;t use the todatetime() function with multiple parameters or it will assume you want a list of datetime. You should look at the datetime() function which will let you create your own datetime more easily. As another approach, you can look into using two a!queryFilters with the&amp;nbsp;greater than or less than operators&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>