Get the date of the nth day of week in a given year and month












7














Introduction



Often, people refer to dates as the "second Friday in August, 2018" or the "fourth Sunday in March, 2012". But it's hard to tell what date that is! Your task to is to write a program that receives a year, a month, a day of the week, and an integer, and output that date.



Challenge




  • For input, you will get a year, a month, a day of week, and a number.


  • You can take input in any reasonable format, like using a string for the day of week or using a zero indexed weekday, or even take the year and month in a single string. Do explain your input format in your answer, though.


  • The integer that tells you which day of week in the month to target will be an integer from 1-5. The integer will never refer to a day of week that does not exist(e.g. the fifth Friday of February 2019, which doesn't exist).


  • Years will always be positive.


  • Your output can be in any reasonable format, including printing your final date. However, please explain your output format un your answer.


  • Providing the year and month in the output is optional. Also, you may assume the date is valid.



Example Input and Output



Consider this input, with the format being taking in the year as a 4 digit number, month as an integer, day of week as string, and the ordinal number as an integer:




2019, 3, Saturday, 2




Output:




March 9




This is code-golf, so shortest answer wins.










share|improve this question




















  • 1




    I thought I might be able to use GNU date, but amusingly, the parser has an... interesting interpretation here.
    – Doorknob
    2 hours ago
















7














Introduction



Often, people refer to dates as the "second Friday in August, 2018" or the "fourth Sunday in March, 2012". But it's hard to tell what date that is! Your task to is to write a program that receives a year, a month, a day of the week, and an integer, and output that date.



Challenge




  • For input, you will get a year, a month, a day of week, and a number.


  • You can take input in any reasonable format, like using a string for the day of week or using a zero indexed weekday, or even take the year and month in a single string. Do explain your input format in your answer, though.


  • The integer that tells you which day of week in the month to target will be an integer from 1-5. The integer will never refer to a day of week that does not exist(e.g. the fifth Friday of February 2019, which doesn't exist).


  • Years will always be positive.


  • Your output can be in any reasonable format, including printing your final date. However, please explain your output format un your answer.


  • Providing the year and month in the output is optional. Also, you may assume the date is valid.



Example Input and Output



Consider this input, with the format being taking in the year as a 4 digit number, month as an integer, day of week as string, and the ordinal number as an integer:




2019, 3, Saturday, 2




Output:




March 9




This is code-golf, so shortest answer wins.










share|improve this question




















  • 1




    I thought I might be able to use GNU date, but amusingly, the parser has an... interesting interpretation here.
    – Doorknob
    2 hours ago














7












7








7







Introduction



Often, people refer to dates as the "second Friday in August, 2018" or the "fourth Sunday in March, 2012". But it's hard to tell what date that is! Your task to is to write a program that receives a year, a month, a day of the week, and an integer, and output that date.



Challenge




  • For input, you will get a year, a month, a day of week, and a number.


  • You can take input in any reasonable format, like using a string for the day of week or using a zero indexed weekday, or even take the year and month in a single string. Do explain your input format in your answer, though.


  • The integer that tells you which day of week in the month to target will be an integer from 1-5. The integer will never refer to a day of week that does not exist(e.g. the fifth Friday of February 2019, which doesn't exist).


  • Years will always be positive.


  • Your output can be in any reasonable format, including printing your final date. However, please explain your output format un your answer.


  • Providing the year and month in the output is optional. Also, you may assume the date is valid.



Example Input and Output



Consider this input, with the format being taking in the year as a 4 digit number, month as an integer, day of week as string, and the ordinal number as an integer:




2019, 3, Saturday, 2




Output:




March 9




This is code-golf, so shortest answer wins.










share|improve this question















Introduction



Often, people refer to dates as the "second Friday in August, 2018" or the "fourth Sunday in March, 2012". But it's hard to tell what date that is! Your task to is to write a program that receives a year, a month, a day of the week, and an integer, and output that date.



Challenge




  • For input, you will get a year, a month, a day of week, and a number.


  • You can take input in any reasonable format, like using a string for the day of week or using a zero indexed weekday, or even take the year and month in a single string. Do explain your input format in your answer, though.


  • The integer that tells you which day of week in the month to target will be an integer from 1-5. The integer will never refer to a day of week that does not exist(e.g. the fifth Friday of February 2019, which doesn't exist).


  • Years will always be positive.


  • Your output can be in any reasonable format, including printing your final date. However, please explain your output format un your answer.


  • Providing the year and month in the output is optional. Also, you may assume the date is valid.



Example Input and Output



Consider this input, with the format being taking in the year as a 4 digit number, month as an integer, day of week as string, and the ordinal number as an integer:




2019, 3, Saturday, 2




Output:




March 9




This is code-golf, so shortest answer wins.







code-golf date






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 33 mins ago

























asked 2 hours ago









Embodiment of Ignorance

39212




39212








  • 1




    I thought I might be able to use GNU date, but amusingly, the parser has an... interesting interpretation here.
    – Doorknob
    2 hours ago














  • 1




    I thought I might be able to use GNU date, but amusingly, the parser has an... interesting interpretation here.
    – Doorknob
    2 hours ago








1




1




I thought I might be able to use GNU date, but amusingly, the parser has an... interesting interpretation here.
– Doorknob
2 hours ago




I thought I might be able to use GNU date, but amusingly, the parser has an... interesting interpretation here.
– Doorknob
2 hours ago










5 Answers
5






active

oldest

votes


















1















MATL, 28 27 bytes



'1 'ihYO31:q+t8XOi=!A)i)1XO


This uses three inputs:




  • String with month and year: 'March 2019'

  • String with three letters, first capitalized, indicating day of the week: 'Sat'

  • Number: 2.


Output is a string with day, year and month separated with dashes: 09-Mar-2019.



Try it online!



Explanation



Consider inputs 'March 2019', 'Sat', 2.



'1 '    % Push this string
% STACK: '1 '
ih % Input string: month and year. Concatenate
% STACK: '1 March 2019'
YO % Convert to serial date number
% STACK: 737485
31:q+ % Create vector [0 1 2 ... 31] and add element-wise
% STACK: [737485 737486 737487 ... 737515]
t8XO % Duplicate. Convert to date format 'ddd': day of week in three letters. Gives
% a 2D char array
% STACK: [737485 737486 737487 ... 737515], ['Fri'; 'Sat'; 'Sun'; ...; 'Sun']
i= % Input string: day of week in three letters. Compare element-wise with broadcast
% STACK: [737485 737486 737487 ... 737515],
% [0 0 0; 0 0 0; ...; 1 1 1; 0 0 0; ... 1 1 1; ...]
!A % True for rows containing only 1
% STACK: [737485 737486 737487 ... 737515], [0 0 ... 1 ... 0 ... 1 ...]
) % Index: uses the second vector as a mask into the first
% STACK: [737486 737493 737500 737507 737514]
i) % Input number. Index
% STACK: 737493
1XO % Convert to date format 'dd-mmm-yyyy'. Implicit display
% STACK: '09-Mar-2019'





share|improve this answer































    1














    SmileBASIC, 58 51 bytes



    INPUT M$,D,N
    DTREAD M$+"/01"OUT,,,W?D-W+7*N-7*(W<D)


    Input is in the form YYYY/MM,weekday,n, (weekday 1 = Sunday).

    Output is the day of the month, 1 indexed.

    The test case would be 2019/03,7,29



    Explanation:



    INPUT YEAR_MONTH$,WEEKDAY,N

    'get the day of the week (0 indexed) of the first day in the month
    DTREAD YEAR_MONTH$+"/01" OUT y,m,d,WEEKDAY_1

    'get the day of the month of the first <WEEKDAY>
    '(This might be less than 1, which is fixed later)
    FIRST = (WEEKDAY-WEEKDAY_1)

    'Add 7*N to get the (N+1)th (or Nth, if FIRST was less than 1) <WEEKDAY> in that month.
    FIRST = FIRST + 7*N

    'If FIRST was not less than 1 to begin with, subtract 7 to get the proper date
    PRINT FIRST - 7*(WEEKDAY_1<WEEKDAY)





    share|improve this answer































      0














      JavaScript (ES6), 49 bytes






      f=
      (y,m,d,n)=>(d+6-new Date(y,m,7).getDay())%7+n*7-6

      <div oninput=o.textContent=f(+y.value,+m.value,+d.value,+n.value)>Year: <input id=y type=number value=2019><br>Month: <select id=m><option value=0>Jan<option value=1>Feb<option value=2>Mar<option value=3>Apr<option value=4>May<option value=5>Jun<option value=6>Jul<option value=7>Aug<option value=8>Sep<option value=9>Oct<option value=10>Nov<option value=11>Dec</select><br>Day: <select id=d><option value=0>Sun<option value=1>Mon<option value=2>Tue<option value=3>Wed<option value=4>Thu<option value=5>Fri<option value=6>Sat</select><br>Count: <input id=n type=number value=1 min=1 max=5><pre id=o>





      Month and day of week (starting on Sunday) are zero-indexed.






      share|improve this answer























      • Is the day of week in the format Sunday-Saturday or Monday-Sunday?
        – Embodiment of Ignorance
        22 mins ago










      • @EmbodimentofIgnorance Sorry, I knew I had forgotten something. (The snippet now uses select to make it easier.)
        – Neil
        19 mins ago










      • @EmbodimentofIgnorance, Sunday is 0 in JS.
        – Shaggy
        18 mins ago










      • Oh. I didn't know that, I'm not that familiar with Javascript.
        – Embodiment of Ignorance
        18 mins ago



















      0















      PHP, 46, 43 bytes





      function f($s){echo date(d,strtotime($s));}


      Try it online!



      The function receives as input a string like "second saturday of March 2019"



      The function returns the day number.






      share|improve this answer































        0














        Japt, 19 17 14 bytes



        Input is: year, 0-based index of month, 0-based index of day & n.



        _XµW¶Ze}f@ÐUVX


        Try it






        share|improve this answer























          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          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: "200"
          };
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fcodegolf.stackexchange.com%2fquestions%2f178227%2fget-the-date-of-the-nth-day-of-week-in-a-given-year-and-month%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1















          MATL, 28 27 bytes



          '1 'ihYO31:q+t8XOi=!A)i)1XO


          This uses three inputs:




          • String with month and year: 'March 2019'

          • String with three letters, first capitalized, indicating day of the week: 'Sat'

          • Number: 2.


          Output is a string with day, year and month separated with dashes: 09-Mar-2019.



          Try it online!



          Explanation



          Consider inputs 'March 2019', 'Sat', 2.



          '1 '    % Push this string
          % STACK: '1 '
          ih % Input string: month and year. Concatenate
          % STACK: '1 March 2019'
          YO % Convert to serial date number
          % STACK: 737485
          31:q+ % Create vector [0 1 2 ... 31] and add element-wise
          % STACK: [737485 737486 737487 ... 737515]
          t8XO % Duplicate. Convert to date format 'ddd': day of week in three letters. Gives
          % a 2D char array
          % STACK: [737485 737486 737487 ... 737515], ['Fri'; 'Sat'; 'Sun'; ...; 'Sun']
          i= % Input string: day of week in three letters. Compare element-wise with broadcast
          % STACK: [737485 737486 737487 ... 737515],
          % [0 0 0; 0 0 0; ...; 1 1 1; 0 0 0; ... 1 1 1; ...]
          !A % True for rows containing only 1
          % STACK: [737485 737486 737487 ... 737515], [0 0 ... 1 ... 0 ... 1 ...]
          ) % Index: uses the second vector as a mask into the first
          % STACK: [737486 737493 737500 737507 737514]
          i) % Input number. Index
          % STACK: 737493
          1XO % Convert to date format 'dd-mmm-yyyy'. Implicit display
          % STACK: '09-Mar-2019'





          share|improve this answer




























            1















            MATL, 28 27 bytes



            '1 'ihYO31:q+t8XOi=!A)i)1XO


            This uses three inputs:




            • String with month and year: 'March 2019'

            • String with three letters, first capitalized, indicating day of the week: 'Sat'

            • Number: 2.


            Output is a string with day, year and month separated with dashes: 09-Mar-2019.



            Try it online!



            Explanation



            Consider inputs 'March 2019', 'Sat', 2.



            '1 '    % Push this string
            % STACK: '1 '
            ih % Input string: month and year. Concatenate
            % STACK: '1 March 2019'
            YO % Convert to serial date number
            % STACK: 737485
            31:q+ % Create vector [0 1 2 ... 31] and add element-wise
            % STACK: [737485 737486 737487 ... 737515]
            t8XO % Duplicate. Convert to date format 'ddd': day of week in three letters. Gives
            % a 2D char array
            % STACK: [737485 737486 737487 ... 737515], ['Fri'; 'Sat'; 'Sun'; ...; 'Sun']
            i= % Input string: day of week in three letters. Compare element-wise with broadcast
            % STACK: [737485 737486 737487 ... 737515],
            % [0 0 0; 0 0 0; ...; 1 1 1; 0 0 0; ... 1 1 1; ...]
            !A % True for rows containing only 1
            % STACK: [737485 737486 737487 ... 737515], [0 0 ... 1 ... 0 ... 1 ...]
            ) % Index: uses the second vector as a mask into the first
            % STACK: [737486 737493 737500 737507 737514]
            i) % Input number. Index
            % STACK: 737493
            1XO % Convert to date format 'dd-mmm-yyyy'. Implicit display
            % STACK: '09-Mar-2019'





            share|improve this answer


























              1












              1








              1







              MATL, 28 27 bytes



              '1 'ihYO31:q+t8XOi=!A)i)1XO


              This uses three inputs:




              • String with month and year: 'March 2019'

              • String with three letters, first capitalized, indicating day of the week: 'Sat'

              • Number: 2.


              Output is a string with day, year and month separated with dashes: 09-Mar-2019.



              Try it online!



              Explanation



              Consider inputs 'March 2019', 'Sat', 2.



              '1 '    % Push this string
              % STACK: '1 '
              ih % Input string: month and year. Concatenate
              % STACK: '1 March 2019'
              YO % Convert to serial date number
              % STACK: 737485
              31:q+ % Create vector [0 1 2 ... 31] and add element-wise
              % STACK: [737485 737486 737487 ... 737515]
              t8XO % Duplicate. Convert to date format 'ddd': day of week in three letters. Gives
              % a 2D char array
              % STACK: [737485 737486 737487 ... 737515], ['Fri'; 'Sat'; 'Sun'; ...; 'Sun']
              i= % Input string: day of week in three letters. Compare element-wise with broadcast
              % STACK: [737485 737486 737487 ... 737515],
              % [0 0 0; 0 0 0; ...; 1 1 1; 0 0 0; ... 1 1 1; ...]
              !A % True for rows containing only 1
              % STACK: [737485 737486 737487 ... 737515], [0 0 ... 1 ... 0 ... 1 ...]
              ) % Index: uses the second vector as a mask into the first
              % STACK: [737486 737493 737500 737507 737514]
              i) % Input number. Index
              % STACK: 737493
              1XO % Convert to date format 'dd-mmm-yyyy'. Implicit display
              % STACK: '09-Mar-2019'





              share|improve this answer















              MATL, 28 27 bytes



              '1 'ihYO31:q+t8XOi=!A)i)1XO


              This uses three inputs:




              • String with month and year: 'March 2019'

              • String with three letters, first capitalized, indicating day of the week: 'Sat'

              • Number: 2.


              Output is a string with day, year and month separated with dashes: 09-Mar-2019.



              Try it online!



              Explanation



              Consider inputs 'March 2019', 'Sat', 2.



              '1 '    % Push this string
              % STACK: '1 '
              ih % Input string: month and year. Concatenate
              % STACK: '1 March 2019'
              YO % Convert to serial date number
              % STACK: 737485
              31:q+ % Create vector [0 1 2 ... 31] and add element-wise
              % STACK: [737485 737486 737487 ... 737515]
              t8XO % Duplicate. Convert to date format 'ddd': day of week in three letters. Gives
              % a 2D char array
              % STACK: [737485 737486 737487 ... 737515], ['Fri'; 'Sat'; 'Sun'; ...; 'Sun']
              i= % Input string: day of week in three letters. Compare element-wise with broadcast
              % STACK: [737485 737486 737487 ... 737515],
              % [0 0 0; 0 0 0; ...; 1 1 1; 0 0 0; ... 1 1 1; ...]
              !A % True for rows containing only 1
              % STACK: [737485 737486 737487 ... 737515], [0 0 ... 1 ... 0 ... 1 ...]
              ) % Index: uses the second vector as a mask into the first
              % STACK: [737486 737493 737500 737507 737514]
              i) % Input number. Index
              % STACK: 737493
              1XO % Convert to date format 'dd-mmm-yyyy'. Implicit display
              % STACK: '09-Mar-2019'






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited 52 mins ago

























              answered 1 hour ago









              Luis Mendo

              74k886291




              74k886291























                  1














                  SmileBASIC, 58 51 bytes



                  INPUT M$,D,N
                  DTREAD M$+"/01"OUT,,,W?D-W+7*N-7*(W<D)


                  Input is in the form YYYY/MM,weekday,n, (weekday 1 = Sunday).

                  Output is the day of the month, 1 indexed.

                  The test case would be 2019/03,7,29



                  Explanation:



                  INPUT YEAR_MONTH$,WEEKDAY,N

                  'get the day of the week (0 indexed) of the first day in the month
                  DTREAD YEAR_MONTH$+"/01" OUT y,m,d,WEEKDAY_1

                  'get the day of the month of the first <WEEKDAY>
                  '(This might be less than 1, which is fixed later)
                  FIRST = (WEEKDAY-WEEKDAY_1)

                  'Add 7*N to get the (N+1)th (or Nth, if FIRST was less than 1) <WEEKDAY> in that month.
                  FIRST = FIRST + 7*N

                  'If FIRST was not less than 1 to begin with, subtract 7 to get the proper date
                  PRINT FIRST - 7*(WEEKDAY_1<WEEKDAY)





                  share|improve this answer




























                    1














                    SmileBASIC, 58 51 bytes



                    INPUT M$,D,N
                    DTREAD M$+"/01"OUT,,,W?D-W+7*N-7*(W<D)


                    Input is in the form YYYY/MM,weekday,n, (weekday 1 = Sunday).

                    Output is the day of the month, 1 indexed.

                    The test case would be 2019/03,7,29



                    Explanation:



                    INPUT YEAR_MONTH$,WEEKDAY,N

                    'get the day of the week (0 indexed) of the first day in the month
                    DTREAD YEAR_MONTH$+"/01" OUT y,m,d,WEEKDAY_1

                    'get the day of the month of the first <WEEKDAY>
                    '(This might be less than 1, which is fixed later)
                    FIRST = (WEEKDAY-WEEKDAY_1)

                    'Add 7*N to get the (N+1)th (or Nth, if FIRST was less than 1) <WEEKDAY> in that month.
                    FIRST = FIRST + 7*N

                    'If FIRST was not less than 1 to begin with, subtract 7 to get the proper date
                    PRINT FIRST - 7*(WEEKDAY_1<WEEKDAY)





                    share|improve this answer


























                      1












                      1








                      1






                      SmileBASIC, 58 51 bytes



                      INPUT M$,D,N
                      DTREAD M$+"/01"OUT,,,W?D-W+7*N-7*(W<D)


                      Input is in the form YYYY/MM,weekday,n, (weekday 1 = Sunday).

                      Output is the day of the month, 1 indexed.

                      The test case would be 2019/03,7,29



                      Explanation:



                      INPUT YEAR_MONTH$,WEEKDAY,N

                      'get the day of the week (0 indexed) of the first day in the month
                      DTREAD YEAR_MONTH$+"/01" OUT y,m,d,WEEKDAY_1

                      'get the day of the month of the first <WEEKDAY>
                      '(This might be less than 1, which is fixed later)
                      FIRST = (WEEKDAY-WEEKDAY_1)

                      'Add 7*N to get the (N+1)th (or Nth, if FIRST was less than 1) <WEEKDAY> in that month.
                      FIRST = FIRST + 7*N

                      'If FIRST was not less than 1 to begin with, subtract 7 to get the proper date
                      PRINT FIRST - 7*(WEEKDAY_1<WEEKDAY)





                      share|improve this answer














                      SmileBASIC, 58 51 bytes



                      INPUT M$,D,N
                      DTREAD M$+"/01"OUT,,,W?D-W+7*N-7*(W<D)


                      Input is in the form YYYY/MM,weekday,n, (weekday 1 = Sunday).

                      Output is the day of the month, 1 indexed.

                      The test case would be 2019/03,7,29



                      Explanation:



                      INPUT YEAR_MONTH$,WEEKDAY,N

                      'get the day of the week (0 indexed) of the first day in the month
                      DTREAD YEAR_MONTH$+"/01" OUT y,m,d,WEEKDAY_1

                      'get the day of the month of the first <WEEKDAY>
                      '(This might be less than 1, which is fixed later)
                      FIRST = (WEEKDAY-WEEKDAY_1)

                      'Add 7*N to get the (N+1)th (or Nth, if FIRST was less than 1) <WEEKDAY> in that month.
                      FIRST = FIRST + 7*N

                      'If FIRST was not less than 1 to begin with, subtract 7 to get the proper date
                      PRINT FIRST - 7*(WEEKDAY_1<WEEKDAY)






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 5 mins ago

























                      answered 33 mins ago









                      12Me21

                      5,44711236




                      5,44711236























                          0














                          JavaScript (ES6), 49 bytes






                          f=
                          (y,m,d,n)=>(d+6-new Date(y,m,7).getDay())%7+n*7-6

                          <div oninput=o.textContent=f(+y.value,+m.value,+d.value,+n.value)>Year: <input id=y type=number value=2019><br>Month: <select id=m><option value=0>Jan<option value=1>Feb<option value=2>Mar<option value=3>Apr<option value=4>May<option value=5>Jun<option value=6>Jul<option value=7>Aug<option value=8>Sep<option value=9>Oct<option value=10>Nov<option value=11>Dec</select><br>Day: <select id=d><option value=0>Sun<option value=1>Mon<option value=2>Tue<option value=3>Wed<option value=4>Thu<option value=5>Fri<option value=6>Sat</select><br>Count: <input id=n type=number value=1 min=1 max=5><pre id=o>





                          Month and day of week (starting on Sunday) are zero-indexed.






                          share|improve this answer























                          • Is the day of week in the format Sunday-Saturday or Monday-Sunday?
                            – Embodiment of Ignorance
                            22 mins ago










                          • @EmbodimentofIgnorance Sorry, I knew I had forgotten something. (The snippet now uses select to make it easier.)
                            – Neil
                            19 mins ago










                          • @EmbodimentofIgnorance, Sunday is 0 in JS.
                            – Shaggy
                            18 mins ago










                          • Oh. I didn't know that, I'm not that familiar with Javascript.
                            – Embodiment of Ignorance
                            18 mins ago
















                          0














                          JavaScript (ES6), 49 bytes






                          f=
                          (y,m,d,n)=>(d+6-new Date(y,m,7).getDay())%7+n*7-6

                          <div oninput=o.textContent=f(+y.value,+m.value,+d.value,+n.value)>Year: <input id=y type=number value=2019><br>Month: <select id=m><option value=0>Jan<option value=1>Feb<option value=2>Mar<option value=3>Apr<option value=4>May<option value=5>Jun<option value=6>Jul<option value=7>Aug<option value=8>Sep<option value=9>Oct<option value=10>Nov<option value=11>Dec</select><br>Day: <select id=d><option value=0>Sun<option value=1>Mon<option value=2>Tue<option value=3>Wed<option value=4>Thu<option value=5>Fri<option value=6>Sat</select><br>Count: <input id=n type=number value=1 min=1 max=5><pre id=o>





                          Month and day of week (starting on Sunday) are zero-indexed.






                          share|improve this answer























                          • Is the day of week in the format Sunday-Saturday or Monday-Sunday?
                            – Embodiment of Ignorance
                            22 mins ago










                          • @EmbodimentofIgnorance Sorry, I knew I had forgotten something. (The snippet now uses select to make it easier.)
                            – Neil
                            19 mins ago










                          • @EmbodimentofIgnorance, Sunday is 0 in JS.
                            – Shaggy
                            18 mins ago










                          • Oh. I didn't know that, I'm not that familiar with Javascript.
                            – Embodiment of Ignorance
                            18 mins ago














                          0












                          0








                          0






                          JavaScript (ES6), 49 bytes






                          f=
                          (y,m,d,n)=>(d+6-new Date(y,m,7).getDay())%7+n*7-6

                          <div oninput=o.textContent=f(+y.value,+m.value,+d.value,+n.value)>Year: <input id=y type=number value=2019><br>Month: <select id=m><option value=0>Jan<option value=1>Feb<option value=2>Mar<option value=3>Apr<option value=4>May<option value=5>Jun<option value=6>Jul<option value=7>Aug<option value=8>Sep<option value=9>Oct<option value=10>Nov<option value=11>Dec</select><br>Day: <select id=d><option value=0>Sun<option value=1>Mon<option value=2>Tue<option value=3>Wed<option value=4>Thu<option value=5>Fri<option value=6>Sat</select><br>Count: <input id=n type=number value=1 min=1 max=5><pre id=o>





                          Month and day of week (starting on Sunday) are zero-indexed.






                          share|improve this answer














                          JavaScript (ES6), 49 bytes






                          f=
                          (y,m,d,n)=>(d+6-new Date(y,m,7).getDay())%7+n*7-6

                          <div oninput=o.textContent=f(+y.value,+m.value,+d.value,+n.value)>Year: <input id=y type=number value=2019><br>Month: <select id=m><option value=0>Jan<option value=1>Feb<option value=2>Mar<option value=3>Apr<option value=4>May<option value=5>Jun<option value=6>Jul<option value=7>Aug<option value=8>Sep<option value=9>Oct<option value=10>Nov<option value=11>Dec</select><br>Day: <select id=d><option value=0>Sun<option value=1>Mon<option value=2>Tue<option value=3>Wed<option value=4>Thu<option value=5>Fri<option value=6>Sat</select><br>Count: <input id=n type=number value=1 min=1 max=5><pre id=o>





                          Month and day of week (starting on Sunday) are zero-indexed.






                          f=
                          (y,m,d,n)=>(d+6-new Date(y,m,7).getDay())%7+n*7-6

                          <div oninput=o.textContent=f(+y.value,+m.value,+d.value,+n.value)>Year: <input id=y type=number value=2019><br>Month: <select id=m><option value=0>Jan<option value=1>Feb<option value=2>Mar<option value=3>Apr<option value=4>May<option value=5>Jun<option value=6>Jul<option value=7>Aug<option value=8>Sep<option value=9>Oct<option value=10>Nov<option value=11>Dec</select><br>Day: <select id=d><option value=0>Sun<option value=1>Mon<option value=2>Tue<option value=3>Wed<option value=4>Thu<option value=5>Fri<option value=6>Sat</select><br>Count: <input id=n type=number value=1 min=1 max=5><pre id=o>





                          f=
                          (y,m,d,n)=>(d+6-new Date(y,m,7).getDay())%7+n*7-6

                          <div oninput=o.textContent=f(+y.value,+m.value,+d.value,+n.value)>Year: <input id=y type=number value=2019><br>Month: <select id=m><option value=0>Jan<option value=1>Feb<option value=2>Mar<option value=3>Apr<option value=4>May<option value=5>Jun<option value=6>Jul<option value=7>Aug<option value=8>Sep<option value=9>Oct<option value=10>Nov<option value=11>Dec</select><br>Day: <select id=d><option value=0>Sun<option value=1>Mon<option value=2>Tue<option value=3>Wed<option value=4>Thu<option value=5>Fri<option value=6>Sat</select><br>Count: <input id=n type=number value=1 min=1 max=5><pre id=o>






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited 20 mins ago

























                          answered 24 mins ago









                          Neil

                          79.4k744177




                          79.4k744177












                          • Is the day of week in the format Sunday-Saturday or Monday-Sunday?
                            – Embodiment of Ignorance
                            22 mins ago










                          • @EmbodimentofIgnorance Sorry, I knew I had forgotten something. (The snippet now uses select to make it easier.)
                            – Neil
                            19 mins ago










                          • @EmbodimentofIgnorance, Sunday is 0 in JS.
                            – Shaggy
                            18 mins ago










                          • Oh. I didn't know that, I'm not that familiar with Javascript.
                            – Embodiment of Ignorance
                            18 mins ago


















                          • Is the day of week in the format Sunday-Saturday or Monday-Sunday?
                            – Embodiment of Ignorance
                            22 mins ago










                          • @EmbodimentofIgnorance Sorry, I knew I had forgotten something. (The snippet now uses select to make it easier.)
                            – Neil
                            19 mins ago










                          • @EmbodimentofIgnorance, Sunday is 0 in JS.
                            – Shaggy
                            18 mins ago










                          • Oh. I didn't know that, I'm not that familiar with Javascript.
                            – Embodiment of Ignorance
                            18 mins ago
















                          Is the day of week in the format Sunday-Saturday or Monday-Sunday?
                          – Embodiment of Ignorance
                          22 mins ago




                          Is the day of week in the format Sunday-Saturday or Monday-Sunday?
                          – Embodiment of Ignorance
                          22 mins ago












                          @EmbodimentofIgnorance Sorry, I knew I had forgotten something. (The snippet now uses select to make it easier.)
                          – Neil
                          19 mins ago




                          @EmbodimentofIgnorance Sorry, I knew I had forgotten something. (The snippet now uses select to make it easier.)
                          – Neil
                          19 mins ago












                          @EmbodimentofIgnorance, Sunday is 0 in JS.
                          – Shaggy
                          18 mins ago




                          @EmbodimentofIgnorance, Sunday is 0 in JS.
                          – Shaggy
                          18 mins ago












                          Oh. I didn't know that, I'm not that familiar with Javascript.
                          – Embodiment of Ignorance
                          18 mins ago




                          Oh. I didn't know that, I'm not that familiar with Javascript.
                          – Embodiment of Ignorance
                          18 mins ago











                          0















                          PHP, 46, 43 bytes





                          function f($s){echo date(d,strtotime($s));}


                          Try it online!



                          The function receives as input a string like "second saturday of March 2019"



                          The function returns the day number.






                          share|improve this answer




























                            0















                            PHP, 46, 43 bytes





                            function f($s){echo date(d,strtotime($s));}


                            Try it online!



                            The function receives as input a string like "second saturday of March 2019"



                            The function returns the day number.






                            share|improve this answer


























                              0












                              0








                              0







                              PHP, 46, 43 bytes





                              function f($s){echo date(d,strtotime($s));}


                              Try it online!



                              The function receives as input a string like "second saturday of March 2019"



                              The function returns the day number.






                              share|improve this answer















                              PHP, 46, 43 bytes





                              function f($s){echo date(d,strtotime($s));}


                              Try it online!



                              The function receives as input a string like "second saturday of March 2019"



                              The function returns the day number.







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited 7 mins ago

























                              answered 2 hours ago









                              Кирилл Малышев

                              40115




                              40115























                                  0














                                  Japt, 19 17 14 bytes



                                  Input is: year, 0-based index of month, 0-based index of day & n.



                                  _XµW¶Ze}f@ÐUVX


                                  Try it






                                  share|improve this answer




























                                    0














                                    Japt, 19 17 14 bytes



                                    Input is: year, 0-based index of month, 0-based index of day & n.



                                    _XµW¶Ze}f@ÐUVX


                                    Try it






                                    share|improve this answer


























                                      0












                                      0








                                      0






                                      Japt, 19 17 14 bytes



                                      Input is: year, 0-based index of month, 0-based index of day & n.



                                      _XµW¶Ze}f@ÐUVX


                                      Try it






                                      share|improve this answer














                                      Japt, 19 17 14 bytes



                                      Input is: year, 0-based index of month, 0-based index of day & n.



                                      _XµW¶Ze}f@ÐUVX


                                      Try it







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 53 secs ago

























                                      answered 12 mins ago









                                      Shaggy

                                      18.9k21666




                                      18.9k21666






























                                          draft saved

                                          draft discarded




















































                                          If this is an answer to a challenge…




                                          • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                          • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                            Explanations of your answer make it more interesting to read and are very much encouraged.


                                          • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                          More generally…




                                          • …Please make sure to answer the question and provide sufficient detail.


                                          • …Avoid asking for help, clarification or responding to other answers (use comments instead).






                                          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                          Please pay close attention to the following guidance:


                                          • 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%2fcodegolf.stackexchange.com%2fquestions%2f178227%2fget-the-date-of-the-nth-day-of-week-in-a-given-year-and-month%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







                                          Popular posts from this blog

                                          Morgemoulin

                                          Scott Moir

                                          Souastre