MS Access SQL - How to pull last 13 months data from the first of the first month?










0















I tried the below code to pull last 13 months of data. But it is not pulling from the 1st of the month. How can I modify it to pull data from the first day of the month?
For e.g. If I am running it today (11/13/18), I want data from 11/1/17 to today.



 SELECT * FROM MyTable T 
WHERE T.[Date Joined] >= DATEADD("m", -13, DATE());









share|improve this question




























    0















    I tried the below code to pull last 13 months of data. But it is not pulling from the 1st of the month. How can I modify it to pull data from the first day of the month?
    For e.g. If I am running it today (11/13/18), I want data from 11/1/17 to today.



     SELECT * FROM MyTable T 
    WHERE T.[Date Joined] >= DATEADD("m", -13, DATE());









    share|improve this question


























      0












      0








      0








      I tried the below code to pull last 13 months of data. But it is not pulling from the 1st of the month. How can I modify it to pull data from the first day of the month?
      For e.g. If I am running it today (11/13/18), I want data from 11/1/17 to today.



       SELECT * FROM MyTable T 
      WHERE T.[Date Joined] >= DATEADD("m", -13, DATE());









      share|improve this question
















      I tried the below code to pull last 13 months of data. But it is not pulling from the 1st of the month. How can I modify it to pull data from the first day of the month?
      For e.g. If I am running it today (11/13/18), I want data from 11/1/17 to today.



       SELECT * FROM MyTable T 
      WHERE T.[Date Joined] >= DATEADD("m", -13, DATE());






      sql ms-access ms-access-2016






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 13 '18 at 17:23









      Gordon Linoff

      767k35300402




      767k35300402










      asked Nov 13 '18 at 17:23









      SKaySKay

      51




      51






















          2 Answers
          2






          active

          oldest

          votes


















          0














          You need to change the day to 1 as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("d", -(DAY(Date())-1),DATEADD("m", -13, DATE());


          Or by using DATESERIAL() function which return a DATE from parts as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("m", -13, DATESERIAL(YEAR(Date()), MONTH(DATE()), 1))


          It will get the YEAR part from the date which is 2018 in your case, then get the MONTH part which is 11 and 1 which is the day and concatenate them to return a DATE as 2018-11-1






          share|improve this answer

























          • Great job, now you made an exact copy...

            – forpas
            Nov 13 '18 at 17:51











          • Oh yeah that's what you think

            – Sami
            Nov 13 '18 at 17:52











          • Of course it is

            – forpas
            Nov 13 '18 at 17:53











          • Thank you @Sami. I used Dateseriel function.

            – SKay
            Nov 13 '18 at 22:30


















          1














          This:



          SELECT * FROM MyTable T 
          WHERE T.[Date Joined] >= DATEADD("m", -13, Dateserial(year(date()), month(date()),1));


          uses



          Dateserial(year(date()), month(date()),1)


          which gives you the 1st of the current month

          so you subtract from this the 13 months.






          share|improve this answer























          • Thank you @forpas, it worked!

            – SKay
            Nov 13 '18 at 22:28










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286453%2fms-access-sql-how-to-pull-last-13-months-data-from-the-first-of-the-first-mont%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You need to change the day to 1 as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("d", -(DAY(Date())-1),DATEADD("m", -13, DATE());


          Or by using DATESERIAL() function which return a DATE from parts as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("m", -13, DATESERIAL(YEAR(Date()), MONTH(DATE()), 1))


          It will get the YEAR part from the date which is 2018 in your case, then get the MONTH part which is 11 and 1 which is the day and concatenate them to return a DATE as 2018-11-1






          share|improve this answer

























          • Great job, now you made an exact copy...

            – forpas
            Nov 13 '18 at 17:51











          • Oh yeah that's what you think

            – Sami
            Nov 13 '18 at 17:52











          • Of course it is

            – forpas
            Nov 13 '18 at 17:53











          • Thank you @Sami. I used Dateseriel function.

            – SKay
            Nov 13 '18 at 22:30















          0














          You need to change the day to 1 as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("d", -(DAY(Date())-1),DATEADD("m", -13, DATE());


          Or by using DATESERIAL() function which return a DATE from parts as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("m", -13, DATESERIAL(YEAR(Date()), MONTH(DATE()), 1))


          It will get the YEAR part from the date which is 2018 in your case, then get the MONTH part which is 11 and 1 which is the day and concatenate them to return a DATE as 2018-11-1






          share|improve this answer

























          • Great job, now you made an exact copy...

            – forpas
            Nov 13 '18 at 17:51











          • Oh yeah that's what you think

            – Sami
            Nov 13 '18 at 17:52











          • Of course it is

            – forpas
            Nov 13 '18 at 17:53











          • Thank you @Sami. I used Dateseriel function.

            – SKay
            Nov 13 '18 at 22:30













          0












          0








          0







          You need to change the day to 1 as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("d", -(DAY(Date())-1),DATEADD("m", -13, DATE());


          Or by using DATESERIAL() function which return a DATE from parts as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("m", -13, DATESERIAL(YEAR(Date()), MONTH(DATE()), 1))


          It will get the YEAR part from the date which is 2018 in your case, then get the MONTH part which is 11 and 1 which is the day and concatenate them to return a DATE as 2018-11-1






          share|improve this answer















          You need to change the day to 1 as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("d", -(DAY(Date())-1),DATEADD("m", -13, DATE());


          Or by using DATESERIAL() function which return a DATE from parts as



          SELECT * 
          FROM MyTable T
          WHERE T.[Date Joined] >= DATEADD("m", -13, DATESERIAL(YEAR(Date()), MONTH(DATE()), 1))


          It will get the YEAR part from the date which is 2018 in your case, then get the MONTH part which is 11 and 1 which is the day and concatenate them to return a DATE as 2018-11-1







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 17:49

























          answered Nov 13 '18 at 17:35









          SamiSami

          8,72331241




          8,72331241












          • Great job, now you made an exact copy...

            – forpas
            Nov 13 '18 at 17:51











          • Oh yeah that's what you think

            – Sami
            Nov 13 '18 at 17:52











          • Of course it is

            – forpas
            Nov 13 '18 at 17:53











          • Thank you @Sami. I used Dateseriel function.

            – SKay
            Nov 13 '18 at 22:30

















          • Great job, now you made an exact copy...

            – forpas
            Nov 13 '18 at 17:51











          • Oh yeah that's what you think

            – Sami
            Nov 13 '18 at 17:52











          • Of course it is

            – forpas
            Nov 13 '18 at 17:53











          • Thank you @Sami. I used Dateseriel function.

            – SKay
            Nov 13 '18 at 22:30
















          Great job, now you made an exact copy...

          – forpas
          Nov 13 '18 at 17:51





          Great job, now you made an exact copy...

          – forpas
          Nov 13 '18 at 17:51













          Oh yeah that's what you think

          – Sami
          Nov 13 '18 at 17:52





          Oh yeah that's what you think

          – Sami
          Nov 13 '18 at 17:52













          Of course it is

          – forpas
          Nov 13 '18 at 17:53





          Of course it is

          – forpas
          Nov 13 '18 at 17:53













          Thank you @Sami. I used Dateseriel function.

          – SKay
          Nov 13 '18 at 22:30





          Thank you @Sami. I used Dateseriel function.

          – SKay
          Nov 13 '18 at 22:30













          1














          This:



          SELECT * FROM MyTable T 
          WHERE T.[Date Joined] >= DATEADD("m", -13, Dateserial(year(date()), month(date()),1));


          uses



          Dateserial(year(date()), month(date()),1)


          which gives you the 1st of the current month

          so you subtract from this the 13 months.






          share|improve this answer























          • Thank you @forpas, it worked!

            – SKay
            Nov 13 '18 at 22:28















          1














          This:



          SELECT * FROM MyTable T 
          WHERE T.[Date Joined] >= DATEADD("m", -13, Dateserial(year(date()), month(date()),1));


          uses



          Dateserial(year(date()), month(date()),1)


          which gives you the 1st of the current month

          so you subtract from this the 13 months.






          share|improve this answer























          • Thank you @forpas, it worked!

            – SKay
            Nov 13 '18 at 22:28













          1












          1








          1







          This:



          SELECT * FROM MyTable T 
          WHERE T.[Date Joined] >= DATEADD("m", -13, Dateserial(year(date()), month(date()),1));


          uses



          Dateserial(year(date()), month(date()),1)


          which gives you the 1st of the current month

          so you subtract from this the 13 months.






          share|improve this answer













          This:



          SELECT * FROM MyTable T 
          WHERE T.[Date Joined] >= DATEADD("m", -13, Dateserial(year(date()), month(date()),1));


          uses



          Dateserial(year(date()), month(date()),1)


          which gives you the 1st of the current month

          so you subtract from this the 13 months.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 17:40









          forpasforpas

          11k3423




          11k3423












          • Thank you @forpas, it worked!

            – SKay
            Nov 13 '18 at 22:28

















          • Thank you @forpas, it worked!

            – SKay
            Nov 13 '18 at 22:28
















          Thank you @forpas, it worked!

          – SKay
          Nov 13 '18 at 22:28





          Thank you @forpas, it worked!

          – SKay
          Nov 13 '18 at 22:28

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53286453%2fms-access-sql-how-to-pull-last-13-months-data-from-the-first-of-the-first-mont%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto