How to get ISO week numbers from date












0














I would like to get the ISO week number from a given date in string format, where Monday is the first day of the week, and the week that contains the first Thursday of the year is considered to be the first week.



From other answers, I think strftime("2017-11-18", format = "%V") suits my purpose the best.
However it doesn't work on Windows.



Any suggestions for alternatives with only the base package in R?










share|improve this question





























    0














    I would like to get the ISO week number from a given date in string format, where Monday is the first day of the week, and the week that contains the first Thursday of the year is considered to be the first week.



    From other answers, I think strftime("2017-11-18", format = "%V") suits my purpose the best.
    However it doesn't work on Windows.



    Any suggestions for alternatives with only the base package in R?










    share|improve this question



























      0












      0








      0







      I would like to get the ISO week number from a given date in string format, where Monday is the first day of the week, and the week that contains the first Thursday of the year is considered to be the first week.



      From other answers, I think strftime("2017-11-18", format = "%V") suits my purpose the best.
      However it doesn't work on Windows.



      Any suggestions for alternatives with only the base package in R?










      share|improve this question















      I would like to get the ISO week number from a given date in string format, where Monday is the first day of the week, and the week that contains the first Thursday of the year is considered to be the first week.



      From other answers, I think strftime("2017-11-18", format = "%V") suits my purpose the best.
      However it doesn't work on Windows.



      Any suggestions for alternatives with only the base package in R?







      r






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 27 '17 at 11:29









      h3rm4n

      3,218820




      3,218820










      asked Nov 27 '17 at 11:10









      noname

      331113




      331113
























          4 Answers
          4






          active

          oldest

          votes


















          3














          Use the package lubridate



          it has a function isoweek()which gives you the ISOWeek of a given date



          lubridate::isoweek("2017-11-18")
          [1] 46


          Now you just want to use the base packege. Here ist the code from lubridate for the ISO week



          function (x) 
          {
          xday <- make_datetime(year(x), month(x), day(x))
          dn <- 1 + (wday(x) + 5)%%7
          nth <- xday + ddays(4 - dn)
          jan1 <- make_datetime(year(nth), 1, 1)
          1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
          }


          we can take that an make it to something which only uses the base package.



          myIsoweek <- function (x) 
          {
          dateList <- as.list(strsplit(as.character(as.Date(x)),split = "-")[[1]])
          names(dateList) <- c("year","month","day")

          weekday <- as.POSIXlt(x)[["wday"]] + 1

          xday <- ISOdate(dateList$year, dateList$month, dateList$day)
          dn <- 1 + (weekday + 5)%%7
          nth <- xday + 86400*(4 - dn)
          jan1 <- ISOdate(format(nth,format = "%Y"), 1, 1)
          1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
          }





          share|improve this answer























          • THe OP wants to use just base R packages ...
            – J_F
            Nov 27 '17 at 11:41










          • Due to the license I cannot use the lubridate library. That's why I'm asking for only base R packages.
            – noname
            Nov 27 '17 at 12:01










          • Hi, I updatet my post to only use the base package
            – Bertil Baron
            Nov 27 '17 at 12:46










          • Great, it works perfectly!
            – noname
            Nov 27 '17 at 12:54










          • It has the same license as R so if you can't use that license then you can't use R either.
            – G. Grothendieck
            Nov 27 '17 at 13:25



















          1














          data.table has an implementation of isoweek which you might want to just port (it's easy to replicate with base functionality)



          # data.table approach:
          isoweek <- function(x) {
          x = as.IDate(x) # number of days since 1 Jan 1970 (a Thurs)
          nearest_thurs = as.IDate(7L * (as.integer(x + 3L) %/% 7L))
          year_start <- as.IDate(format(nearest_thurs, '%Y-01-01'))
          1L + (nearest_thurs - year_start) %/% 7L
          }


          Ported to be strictly base:



          isoweek <- function(x) {
          x = as.Date(x) # number of days since 1 Jan 1970 (a Thurs)
          nearest_thurs = as.Date(7L * (as.integer(x + 3L) %/% 7L), origin = '1970-01-01')
          year_start <- as.Date(format(nearest_thurs, '%Y-01-01'))
          1L + (nearest_thurs - year_start) %/% 7L
          }





          share|improve this answer































            0














            I believe strftime("2017-11-18", format = "%W") should work in Windows.






            share|improve this answer





















            • Hi Cihan, I've tried %W, it doesn't give the ISO week. I saw in it's documentation it mentions "first Monday of the year as day 1 of week 1"
              – noname
              Nov 27 '17 at 11:28






            • 1




              You are correct. Can you try format(as.POSIXct(as.Date("2017-11-18")), "%V") instead? I've found a discussion that's on this topic here: r.789695.n4.nabble.com/…
              – Cihan Ceyhan
              Nov 27 '17 at 11:35










            • It returns the same empty string for me.
              – noname
              Nov 27 '17 at 12:01



















            0














            This should work



            format(as.Date("2017-02-015"),"%W")





            share|improve this answer























            • Hi Smiley, this only give the day of the week instead of the week number. Also it use Sunday as first day of the week.
              – noname
              Nov 27 '17 at 11:32










            • Hi noname, sorry i meant the capital "W" but still it wouldn't help you answer with the need of monday to be first day of the week.
              – Smiley Bcc
              Nov 27 '17 at 11:40










            • If there is really no way, you can consider using cut() function to manually define your own customized week
              – Smiley Bcc
              Nov 27 '17 at 11:42











            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%2f47509567%2fhow-to-get-iso-week-numbers-from-date%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            4 Answers
            4






            active

            oldest

            votes








            4 Answers
            4






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            3














            Use the package lubridate



            it has a function isoweek()which gives you the ISOWeek of a given date



            lubridate::isoweek("2017-11-18")
            [1] 46


            Now you just want to use the base packege. Here ist the code from lubridate for the ISO week



            function (x) 
            {
            xday <- make_datetime(year(x), month(x), day(x))
            dn <- 1 + (wday(x) + 5)%%7
            nth <- xday + ddays(4 - dn)
            jan1 <- make_datetime(year(nth), 1, 1)
            1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
            }


            we can take that an make it to something which only uses the base package.



            myIsoweek <- function (x) 
            {
            dateList <- as.list(strsplit(as.character(as.Date(x)),split = "-")[[1]])
            names(dateList) <- c("year","month","day")

            weekday <- as.POSIXlt(x)[["wday"]] + 1

            xday <- ISOdate(dateList$year, dateList$month, dateList$day)
            dn <- 1 + (weekday + 5)%%7
            nth <- xday + 86400*(4 - dn)
            jan1 <- ISOdate(format(nth,format = "%Y"), 1, 1)
            1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
            }





            share|improve this answer























            • THe OP wants to use just base R packages ...
              – J_F
              Nov 27 '17 at 11:41










            • Due to the license I cannot use the lubridate library. That's why I'm asking for only base R packages.
              – noname
              Nov 27 '17 at 12:01










            • Hi, I updatet my post to only use the base package
              – Bertil Baron
              Nov 27 '17 at 12:46










            • Great, it works perfectly!
              – noname
              Nov 27 '17 at 12:54










            • It has the same license as R so if you can't use that license then you can't use R either.
              – G. Grothendieck
              Nov 27 '17 at 13:25
















            3














            Use the package lubridate



            it has a function isoweek()which gives you the ISOWeek of a given date



            lubridate::isoweek("2017-11-18")
            [1] 46


            Now you just want to use the base packege. Here ist the code from lubridate for the ISO week



            function (x) 
            {
            xday <- make_datetime(year(x), month(x), day(x))
            dn <- 1 + (wday(x) + 5)%%7
            nth <- xday + ddays(4 - dn)
            jan1 <- make_datetime(year(nth), 1, 1)
            1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
            }


            we can take that an make it to something which only uses the base package.



            myIsoweek <- function (x) 
            {
            dateList <- as.list(strsplit(as.character(as.Date(x)),split = "-")[[1]])
            names(dateList) <- c("year","month","day")

            weekday <- as.POSIXlt(x)[["wday"]] + 1

            xday <- ISOdate(dateList$year, dateList$month, dateList$day)
            dn <- 1 + (weekday + 5)%%7
            nth <- xday + 86400*(4 - dn)
            jan1 <- ISOdate(format(nth,format = "%Y"), 1, 1)
            1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
            }





            share|improve this answer























            • THe OP wants to use just base R packages ...
              – J_F
              Nov 27 '17 at 11:41










            • Due to the license I cannot use the lubridate library. That's why I'm asking for only base R packages.
              – noname
              Nov 27 '17 at 12:01










            • Hi, I updatet my post to only use the base package
              – Bertil Baron
              Nov 27 '17 at 12:46










            • Great, it works perfectly!
              – noname
              Nov 27 '17 at 12:54










            • It has the same license as R so if you can't use that license then you can't use R either.
              – G. Grothendieck
              Nov 27 '17 at 13:25














            3












            3








            3






            Use the package lubridate



            it has a function isoweek()which gives you the ISOWeek of a given date



            lubridate::isoweek("2017-11-18")
            [1] 46


            Now you just want to use the base packege. Here ist the code from lubridate for the ISO week



            function (x) 
            {
            xday <- make_datetime(year(x), month(x), day(x))
            dn <- 1 + (wday(x) + 5)%%7
            nth <- xday + ddays(4 - dn)
            jan1 <- make_datetime(year(nth), 1, 1)
            1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
            }


            we can take that an make it to something which only uses the base package.



            myIsoweek <- function (x) 
            {
            dateList <- as.list(strsplit(as.character(as.Date(x)),split = "-")[[1]])
            names(dateList) <- c("year","month","day")

            weekday <- as.POSIXlt(x)[["wday"]] + 1

            xday <- ISOdate(dateList$year, dateList$month, dateList$day)
            dn <- 1 + (weekday + 5)%%7
            nth <- xday + 86400*(4 - dn)
            jan1 <- ISOdate(format(nth,format = "%Y"), 1, 1)
            1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
            }





            share|improve this answer














            Use the package lubridate



            it has a function isoweek()which gives you the ISOWeek of a given date



            lubridate::isoweek("2017-11-18")
            [1] 46


            Now you just want to use the base packege. Here ist the code from lubridate for the ISO week



            function (x) 
            {
            xday <- make_datetime(year(x), month(x), day(x))
            dn <- 1 + (wday(x) + 5)%%7
            nth <- xday + ddays(4 - dn)
            jan1 <- make_datetime(year(nth), 1, 1)
            1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
            }


            we can take that an make it to something which only uses the base package.



            myIsoweek <- function (x) 
            {
            dateList <- as.list(strsplit(as.character(as.Date(x)),split = "-")[[1]])
            names(dateList) <- c("year","month","day")

            weekday <- as.POSIXlt(x)[["wday"]] + 1

            xday <- ISOdate(dateList$year, dateList$month, dateList$day)
            dn <- 1 + (weekday + 5)%%7
            nth <- xday + 86400*(4 - dn)
            jan1 <- ISOdate(format(nth,format = "%Y"), 1, 1)
            1L + as.integer(difftime(nth, jan1, units = "days"))%/%7L
            }






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 27 '17 at 12:45

























            answered Nov 27 '17 at 11:35









            Bertil Baron

            2,7121716




            2,7121716












            • THe OP wants to use just base R packages ...
              – J_F
              Nov 27 '17 at 11:41










            • Due to the license I cannot use the lubridate library. That's why I'm asking for only base R packages.
              – noname
              Nov 27 '17 at 12:01










            • Hi, I updatet my post to only use the base package
              – Bertil Baron
              Nov 27 '17 at 12:46










            • Great, it works perfectly!
              – noname
              Nov 27 '17 at 12:54










            • It has the same license as R so if you can't use that license then you can't use R either.
              – G. Grothendieck
              Nov 27 '17 at 13:25


















            • THe OP wants to use just base R packages ...
              – J_F
              Nov 27 '17 at 11:41










            • Due to the license I cannot use the lubridate library. That's why I'm asking for only base R packages.
              – noname
              Nov 27 '17 at 12:01










            • Hi, I updatet my post to only use the base package
              – Bertil Baron
              Nov 27 '17 at 12:46










            • Great, it works perfectly!
              – noname
              Nov 27 '17 at 12:54










            • It has the same license as R so if you can't use that license then you can't use R either.
              – G. Grothendieck
              Nov 27 '17 at 13:25
















            THe OP wants to use just base R packages ...
            – J_F
            Nov 27 '17 at 11:41




            THe OP wants to use just base R packages ...
            – J_F
            Nov 27 '17 at 11:41












            Due to the license I cannot use the lubridate library. That's why I'm asking for only base R packages.
            – noname
            Nov 27 '17 at 12:01




            Due to the license I cannot use the lubridate library. That's why I'm asking for only base R packages.
            – noname
            Nov 27 '17 at 12:01












            Hi, I updatet my post to only use the base package
            – Bertil Baron
            Nov 27 '17 at 12:46




            Hi, I updatet my post to only use the base package
            – Bertil Baron
            Nov 27 '17 at 12:46












            Great, it works perfectly!
            – noname
            Nov 27 '17 at 12:54




            Great, it works perfectly!
            – noname
            Nov 27 '17 at 12:54












            It has the same license as R so if you can't use that license then you can't use R either.
            – G. Grothendieck
            Nov 27 '17 at 13:25




            It has the same license as R so if you can't use that license then you can't use R either.
            – G. Grothendieck
            Nov 27 '17 at 13:25













            1














            data.table has an implementation of isoweek which you might want to just port (it's easy to replicate with base functionality)



            # data.table approach:
            isoweek <- function(x) {
            x = as.IDate(x) # number of days since 1 Jan 1970 (a Thurs)
            nearest_thurs = as.IDate(7L * (as.integer(x + 3L) %/% 7L))
            year_start <- as.IDate(format(nearest_thurs, '%Y-01-01'))
            1L + (nearest_thurs - year_start) %/% 7L
            }


            Ported to be strictly base:



            isoweek <- function(x) {
            x = as.Date(x) # number of days since 1 Jan 1970 (a Thurs)
            nearest_thurs = as.Date(7L * (as.integer(x + 3L) %/% 7L), origin = '1970-01-01')
            year_start <- as.Date(format(nearest_thurs, '%Y-01-01'))
            1L + (nearest_thurs - year_start) %/% 7L
            }





            share|improve this answer




























              1














              data.table has an implementation of isoweek which you might want to just port (it's easy to replicate with base functionality)



              # data.table approach:
              isoweek <- function(x) {
              x = as.IDate(x) # number of days since 1 Jan 1970 (a Thurs)
              nearest_thurs = as.IDate(7L * (as.integer(x + 3L) %/% 7L))
              year_start <- as.IDate(format(nearest_thurs, '%Y-01-01'))
              1L + (nearest_thurs - year_start) %/% 7L
              }


              Ported to be strictly base:



              isoweek <- function(x) {
              x = as.Date(x) # number of days since 1 Jan 1970 (a Thurs)
              nearest_thurs = as.Date(7L * (as.integer(x + 3L) %/% 7L), origin = '1970-01-01')
              year_start <- as.Date(format(nearest_thurs, '%Y-01-01'))
              1L + (nearest_thurs - year_start) %/% 7L
              }





              share|improve this answer


























                1












                1








                1






                data.table has an implementation of isoweek which you might want to just port (it's easy to replicate with base functionality)



                # data.table approach:
                isoweek <- function(x) {
                x = as.IDate(x) # number of days since 1 Jan 1970 (a Thurs)
                nearest_thurs = as.IDate(7L * (as.integer(x + 3L) %/% 7L))
                year_start <- as.IDate(format(nearest_thurs, '%Y-01-01'))
                1L + (nearest_thurs - year_start) %/% 7L
                }


                Ported to be strictly base:



                isoweek <- function(x) {
                x = as.Date(x) # number of days since 1 Jan 1970 (a Thurs)
                nearest_thurs = as.Date(7L * (as.integer(x + 3L) %/% 7L), origin = '1970-01-01')
                year_start <- as.Date(format(nearest_thurs, '%Y-01-01'))
                1L + (nearest_thurs - year_start) %/% 7L
                }





                share|improve this answer














                data.table has an implementation of isoweek which you might want to just port (it's easy to replicate with base functionality)



                # data.table approach:
                isoweek <- function(x) {
                x = as.IDate(x) # number of days since 1 Jan 1970 (a Thurs)
                nearest_thurs = as.IDate(7L * (as.integer(x + 3L) %/% 7L))
                year_start <- as.IDate(format(nearest_thurs, '%Y-01-01'))
                1L + (nearest_thurs - year_start) %/% 7L
                }


                Ported to be strictly base:



                isoweek <- function(x) {
                x = as.Date(x) # number of days since 1 Jan 1970 (a Thurs)
                nearest_thurs = as.Date(7L * (as.integer(x + 3L) %/% 7L), origin = '1970-01-01')
                year_start <- as.Date(format(nearest_thurs, '%Y-01-01'))
                1L + (nearest_thurs - year_start) %/% 7L
                }






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 21 at 9:16

























                answered Nov 20 at 6:05









                MichaelChirico

                19.7k859109




                19.7k859109























                    0














                    I believe strftime("2017-11-18", format = "%W") should work in Windows.






                    share|improve this answer





















                    • Hi Cihan, I've tried %W, it doesn't give the ISO week. I saw in it's documentation it mentions "first Monday of the year as day 1 of week 1"
                      – noname
                      Nov 27 '17 at 11:28






                    • 1




                      You are correct. Can you try format(as.POSIXct(as.Date("2017-11-18")), "%V") instead? I've found a discussion that's on this topic here: r.789695.n4.nabble.com/…
                      – Cihan Ceyhan
                      Nov 27 '17 at 11:35










                    • It returns the same empty string for me.
                      – noname
                      Nov 27 '17 at 12:01
















                    0














                    I believe strftime("2017-11-18", format = "%W") should work in Windows.






                    share|improve this answer





















                    • Hi Cihan, I've tried %W, it doesn't give the ISO week. I saw in it's documentation it mentions "first Monday of the year as day 1 of week 1"
                      – noname
                      Nov 27 '17 at 11:28






                    • 1




                      You are correct. Can you try format(as.POSIXct(as.Date("2017-11-18")), "%V") instead? I've found a discussion that's on this topic here: r.789695.n4.nabble.com/…
                      – Cihan Ceyhan
                      Nov 27 '17 at 11:35










                    • It returns the same empty string for me.
                      – noname
                      Nov 27 '17 at 12:01














                    0












                    0








                    0






                    I believe strftime("2017-11-18", format = "%W") should work in Windows.






                    share|improve this answer












                    I believe strftime("2017-11-18", format = "%W") should work in Windows.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 27 '17 at 11:20









                    Cihan Ceyhan

                    681310




                    681310












                    • Hi Cihan, I've tried %W, it doesn't give the ISO week. I saw in it's documentation it mentions "first Monday of the year as day 1 of week 1"
                      – noname
                      Nov 27 '17 at 11:28






                    • 1




                      You are correct. Can you try format(as.POSIXct(as.Date("2017-11-18")), "%V") instead? I've found a discussion that's on this topic here: r.789695.n4.nabble.com/…
                      – Cihan Ceyhan
                      Nov 27 '17 at 11:35










                    • It returns the same empty string for me.
                      – noname
                      Nov 27 '17 at 12:01


















                    • Hi Cihan, I've tried %W, it doesn't give the ISO week. I saw in it's documentation it mentions "first Monday of the year as day 1 of week 1"
                      – noname
                      Nov 27 '17 at 11:28






                    • 1




                      You are correct. Can you try format(as.POSIXct(as.Date("2017-11-18")), "%V") instead? I've found a discussion that's on this topic here: r.789695.n4.nabble.com/…
                      – Cihan Ceyhan
                      Nov 27 '17 at 11:35










                    • It returns the same empty string for me.
                      – noname
                      Nov 27 '17 at 12:01
















                    Hi Cihan, I've tried %W, it doesn't give the ISO week. I saw in it's documentation it mentions "first Monday of the year as day 1 of week 1"
                    – noname
                    Nov 27 '17 at 11:28




                    Hi Cihan, I've tried %W, it doesn't give the ISO week. I saw in it's documentation it mentions "first Monday of the year as day 1 of week 1"
                    – noname
                    Nov 27 '17 at 11:28




                    1




                    1




                    You are correct. Can you try format(as.POSIXct(as.Date("2017-11-18")), "%V") instead? I've found a discussion that's on this topic here: r.789695.n4.nabble.com/…
                    – Cihan Ceyhan
                    Nov 27 '17 at 11:35




                    You are correct. Can you try format(as.POSIXct(as.Date("2017-11-18")), "%V") instead? I've found a discussion that's on this topic here: r.789695.n4.nabble.com/…
                    – Cihan Ceyhan
                    Nov 27 '17 at 11:35












                    It returns the same empty string for me.
                    – noname
                    Nov 27 '17 at 12:01




                    It returns the same empty string for me.
                    – noname
                    Nov 27 '17 at 12:01











                    0














                    This should work



                    format(as.Date("2017-02-015"),"%W")





                    share|improve this answer























                    • Hi Smiley, this only give the day of the week instead of the week number. Also it use Sunday as first day of the week.
                      – noname
                      Nov 27 '17 at 11:32










                    • Hi noname, sorry i meant the capital "W" but still it wouldn't help you answer with the need of monday to be first day of the week.
                      – Smiley Bcc
                      Nov 27 '17 at 11:40










                    • If there is really no way, you can consider using cut() function to manually define your own customized week
                      – Smiley Bcc
                      Nov 27 '17 at 11:42
















                    0














                    This should work



                    format(as.Date("2017-02-015"),"%W")





                    share|improve this answer























                    • Hi Smiley, this only give the day of the week instead of the week number. Also it use Sunday as first day of the week.
                      – noname
                      Nov 27 '17 at 11:32










                    • Hi noname, sorry i meant the capital "W" but still it wouldn't help you answer with the need of monday to be first day of the week.
                      – Smiley Bcc
                      Nov 27 '17 at 11:40










                    • If there is really no way, you can consider using cut() function to manually define your own customized week
                      – Smiley Bcc
                      Nov 27 '17 at 11:42














                    0












                    0








                    0






                    This should work



                    format(as.Date("2017-02-015"),"%W")





                    share|improve this answer














                    This should work



                    format(as.Date("2017-02-015"),"%W")






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 27 '17 at 11:41

























                    answered Nov 27 '17 at 11:26









                    Smiley Bcc

                    1149




                    1149












                    • Hi Smiley, this only give the day of the week instead of the week number. Also it use Sunday as first day of the week.
                      – noname
                      Nov 27 '17 at 11:32










                    • Hi noname, sorry i meant the capital "W" but still it wouldn't help you answer with the need of monday to be first day of the week.
                      – Smiley Bcc
                      Nov 27 '17 at 11:40










                    • If there is really no way, you can consider using cut() function to manually define your own customized week
                      – Smiley Bcc
                      Nov 27 '17 at 11:42


















                    • Hi Smiley, this only give the day of the week instead of the week number. Also it use Sunday as first day of the week.
                      – noname
                      Nov 27 '17 at 11:32










                    • Hi noname, sorry i meant the capital "W" but still it wouldn't help you answer with the need of monday to be first day of the week.
                      – Smiley Bcc
                      Nov 27 '17 at 11:40










                    • If there is really no way, you can consider using cut() function to manually define your own customized week
                      – Smiley Bcc
                      Nov 27 '17 at 11:42
















                    Hi Smiley, this only give the day of the week instead of the week number. Also it use Sunday as first day of the week.
                    – noname
                    Nov 27 '17 at 11:32




                    Hi Smiley, this only give the day of the week instead of the week number. Also it use Sunday as first day of the week.
                    – noname
                    Nov 27 '17 at 11:32












                    Hi noname, sorry i meant the capital "W" but still it wouldn't help you answer with the need of monday to be first day of the week.
                    – Smiley Bcc
                    Nov 27 '17 at 11:40




                    Hi noname, sorry i meant the capital "W" but still it wouldn't help you answer with the need of monday to be first day of the week.
                    – Smiley Bcc
                    Nov 27 '17 at 11:40












                    If there is really no way, you can consider using cut() function to manually define your own customized week
                    – Smiley Bcc
                    Nov 27 '17 at 11:42




                    If there is really no way, you can consider using cut() function to manually define your own customized week
                    – Smiley Bcc
                    Nov 27 '17 at 11:42


















                    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.





                    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%2fstackoverflow.com%2fquestions%2f47509567%2fhow-to-get-iso-week-numbers-from-date%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

                    Feedback on college project

                    Futebolista

                    Albești (Vaslui)