{"id":1352,"date":"2018-07-30T15:48:18","date_gmt":"2018-07-30T19:48:18","guid":{"rendered":"https:\/\/regina-whipp.com\/blog\/?p=1352"},"modified":"2018-08-15T17:29:42","modified_gmt":"2018-08-15T21:29:42","slug":"getquarters","status":"publish","type":"post","link":"https:\/\/regina-whipp.com\/blog\/?p=1352","title":{"rendered":"Show Quarters Between Two Dates&#8230;"},"content":{"rendered":"<p>Interesting question in a Forum whereby the Poster wanted a list of the Quarters between two dates.\u00a0 While this request doesn&#8217;t come up often when it does there&#8217;s an answer&#8230;<\/p>\n<p>While you *think* you could run this in one query it&#8217;s just not possible because in order for the query to provide the answer it needs data as in dates to process.\u00a0 Other than that you are just going to get the beginning Quarter and the ending Quarter.\u00a0 The query cannot *think* those dates into existence.\u00a0 So, we have to *trick* it into seeing those dates.\u00a0 <em>(You could use this same procedure for projecting months or years, as well.)<\/em><\/p>\n<p><b>Step 1<\/b><br \/>\nIn your database create a table named <strong>tblCount<\/strong> and add one field named <strong>dNumber<\/strong> &#8211; Long Integer and make it a <strong>Primary Key<\/strong>. Start with the number 0(zero) and continue adding until you get to 1724.\u00a0 <em>(Okay, tedious but worth it so just keep lugging away till you get to that number.)<\/em><\/p>\n<p>Side note:\u00a0 A way faster way to get those values in a table is inside a transaction with a QueryDef (posted by MarkK in <a href=\"https:\/\/access-programmers.co.uk\/forums\/\">Access World Forums<\/a>)\u00a0 Just copy\\paste the below code in a new <strong>Module<\/strong> and then put&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n?fInsertNumbers()\r\n<\/pre>\n<p>&#8230;in the <strong>Immediate<\/strong> window and press enter.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nOption Compare Database\r\nOption Explicit\r\nConst SQL As String = &quot;INSERT INTO tblCount(dNumber) VALUES( p0 )&quot;\r\nFunction fInsertNumbers()\r\n'From https:\/\/www.access-programmers.co.uk\/forums\/showthread.php?t=300693\r\n    \r\n    Dim i As Integer\r\n    \r\n    DBEngine.BeginTrans\r\n    With CurrentDb.CreateQueryDef(&quot;&quot;, SQL)\r\n        For i = 1 To 1724\r\n            .Parameters(0) = i\r\n            .Execute\r\n        Next\r\n        .Close\r\n    End With\r\n    DBEngine.CommitTrans\r\n\r\nEnd Function\r\n\r\n<\/pre>\n<p><em><strong>Tip<\/strong>!\u00a0 If you download the sample file below tblCount is included and already populated and Module is included for future use.<\/em><\/p>\n<p><b>Step 2<\/b><br \/>\nCreate a <strong>SELECT<\/strong> query (mine is named <strong>qryGetProjectDays<\/strong>) based off of the Table that has the Project Start Date and End Date and drop <strong>tblCount<\/strong> in and do <span style=\"color: #ff0000;\"><strong>NOT<\/strong> <\/span>create any Joins. You need one field&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nTheDays: DateAdd(&quot;d&quot;,&#x5B;dNumber],&#x5B;pStartDate])\r\n<\/pre>\n<p>and add\u00a0<strong>&lt;=[pEndDate]<\/strong>\u00a0to the <strong>Criteria<\/strong> section of that one field\u00a0(example of what you should have below)&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nSELECT DateAdd(&quot;d&quot;,&#x5B;dNumber],&#x5B;pStartDate]) AS TheDays\r\nFROM tblYourTable, tblCount\r\nWHERE (((DateAdd(&quot;d&quot;,&#x5B;dNumber],&#x5B;pStartDate]))&lt;=&#x5B;pEndDate]))\r\nORDER BY DateAdd(&quot;d&quot;,&#x5B;dNumber],&#x5B;pStartDate]);\r\n<\/pre>\n<p><em><strong>Note<\/strong>: When you preview the query provided you have entered a Start Date and and End Date you will see a record for every day in the Project.<\/em><\/p>\n<p><b>Step 3<\/b><br \/>\nCreate a new <strong>SELECT<\/strong> query and place <strong>qryGetProjectDays<\/strong> (or whatever you named your query) in your new <strong>SELECT<\/strong> query. Place&#8230;<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nCDate(Format(&#x5B;TheDays],&quot;q-yyyy&quot;))\r\n<\/pre>\n<p>&#8230;on the <strong>Field<\/strong> line below (example below).\u00a0 You should now see all the\u00a0<strong>Quarters<\/strong> between two dates entered.<\/p>\n<div>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nSELECT CDate(Format(&#x5B;TheDays],&quot;q-yyyy&quot;)) AS ProjectQuarters\r\nFROM qryGetProjectDays\r\nGROUP BY CDate(Format(&#x5B;TheDays],&quot;q-yyyy&quot;));\r\n<\/pre>\n<\/div>\n<p>All done!\u00a0 You can download the sample database <a href=\"https:\/\/www.access-diva.com\/myzipfiles\/GetQuarters.zip\">here<\/a>.<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1352\" class=\"pvc_stats all  \" data-element-id=\"1352\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/regina-whipp.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Interesting question in a Forum whereby the Poster wanted a list of the Quarters between two dates. While this request doesn&#8217;t come up often when it does there&#8217;s an answer&#8230;<\/p>\n<p>While you *think* you could run this in one query it&#8217;s just not possible because in order for the query to provide the answer it [&#8230;]<\/p>\n<div class=\"pvc_clear\"><\/div>\n<p id=\"pvc_stats_1352\" class=\"pvc_stats all  \" data-element-id=\"1352\" style=\"\"><i class=\"pvc-stats-icon medium\" aria-hidden=\"true\"><svg aria-hidden=\"true\" focusable=\"false\" data-prefix=\"far\" data-icon=\"chart-bar\" role=\"img\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\" class=\"svg-inline--fa fa-chart-bar fa-w-16 fa-2x\"><path fill=\"currentColor\" d=\"M396.8 352h22.4c6.4 0 12.8-6.4 12.8-12.8V108.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v230.4c0 6.4 6.4 12.8 12.8 12.8zm-192 0h22.4c6.4 0 12.8-6.4 12.8-12.8V140.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v198.4c0 6.4 6.4 12.8 12.8 12.8zm96 0h22.4c6.4 0 12.8-6.4 12.8-12.8V204.8c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v134.4c0 6.4 6.4 12.8 12.8 12.8zM496 400H48V80c0-8.84-7.16-16-16-16H16C7.16 64 0 71.16 0 80v336c0 17.67 14.33 32 32 32h464c8.84 0 16-7.16 16-16v-16c0-8.84-7.16-16-16-16zm-387.2-48h22.4c6.4 0 12.8-6.4 12.8-12.8v-70.4c0-6.4-6.4-12.8-12.8-12.8h-22.4c-6.4 0-12.8 6.4-12.8 12.8v70.4c0 6.4 6.4 12.8 12.8 12.8z\" class=\"\"><\/path><\/svg><\/i> <img loading=\"lazy\" decoding=\"async\" width=\"16\" height=\"16\" alt=\"Loading\" src=\"https:\/\/regina-whipp.com\/blog\/wp-content\/plugins\/page-views-count\/ajax-loader-2x.gif\" border=0 \/><\/p>\n<div class=\"pvc_clear\"><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[22],"class_list":["post-1352","post","type-post","status-publish","format-standard","hentry","category-access-tips","tag-queries","odd"],"_links":{"self":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1352"}],"version-history":[{"count":11,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1352\/revisions"}],"predecessor-version":[{"id":1358,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1352\/revisions\/1358"}],"wp:attachment":[{"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/regina-whipp.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}