Converting a list of dates into another format in R?












0















I am attempting to change these lists into another type of format for use in the RJDBC package. The syntax for Oracle will only accept dates in the format of '1-OCT-18'. However, the output of this list is in the format '2018-10-01'.



How can I convert these lists into the format: 1-OCT-18



   begin <- ymd("2017-01-01")+ months(0:21)
last <- ymd("2017-02-01")+ months(0:22)-days(1)









share|improve this question



























    0















    I am attempting to change these lists into another type of format for use in the RJDBC package. The syntax for Oracle will only accept dates in the format of '1-OCT-18'. However, the output of this list is in the format '2018-10-01'.



    How can I convert these lists into the format: 1-OCT-18



       begin <- ymd("2017-01-01")+ months(0:21)
    last <- ymd("2017-02-01")+ months(0:22)-days(1)









    share|improve this question

























      0












      0








      0








      I am attempting to change these lists into another type of format for use in the RJDBC package. The syntax for Oracle will only accept dates in the format of '1-OCT-18'. However, the output of this list is in the format '2018-10-01'.



      How can I convert these lists into the format: 1-OCT-18



         begin <- ymd("2017-01-01")+ months(0:21)
      last <- ymd("2017-02-01")+ months(0:22)-days(1)









      share|improve this question














      I am attempting to change these lists into another type of format for use in the RJDBC package. The syntax for Oracle will only accept dates in the format of '1-OCT-18'. However, the output of this list is in the format '2018-10-01'.



      How can I convert these lists into the format: 1-OCT-18



         begin <- ymd("2017-01-01")+ months(0:21)
      last <- ymd("2017-02-01")+ months(0:22)-days(1)






      r lapply lubridate






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 21:58









      DevinDevin

      77111




      77111
























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can use format, wrapping in toupper for upper-case, and trimws to trim the whitespace created by %e. I used %e in format because it is the Day of the month as decimal number (1–31), with a leading space for a single-digit number. So then we just remove the whitespace afterward.



          trimws(toupper(format(begin, "%e-%b-%y")))
          # [1] "1-JAN-17" "1-FEB-17" "1-MAR-17" "1-APR-17" "1-MAY-17" "1-JUN-17"
          # [7] "1-JUL-17" "1-AUG-17" "1-SEP-17" "1-OCT-17" "1-NOV-17" "1-DEC-17"
          # [13] "1-JAN-18" "1-FEB-18" "1-MAR-18" "1-APR-18" "1-MAY-18" "1-JUN-18"
          # [19] "1-JUL-18" "1-AUG-18" "1-SEP-18" "1-OCT-18"


          For the last vector, you can omit trimws because %e won't generate any whitespace for two-digit numbers.



          toupper(format(last, "%e-%b-%y"))
          # [1] "31-JAN-17" "28-FEB-17" "31-MAR-17" "30-APR-17" "31-MAY-17"
          # [6] "30-JUN-17" "31-JUL-17" "31-AUG-17" "30-SEP-17" "31-OCT-17"
          # [11] "30-NOV-17" "31-DEC-17" "31-JAN-18" "28-FEB-18" "31-MAR-18"
          # [16] "30-APR-18" "31-MAY-18" "30-JUN-18" "31-JUL-18" "31-AUG-18"
          # [21] "30-SEP-18" "31-OCT-18" "30-NOV-18"





          share|improve this answer

























            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%2f53402224%2fconverting-a-list-of-dates-into-another-format-in-r%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You can use format, wrapping in toupper for upper-case, and trimws to trim the whitespace created by %e. I used %e in format because it is the Day of the month as decimal number (1–31), with a leading space for a single-digit number. So then we just remove the whitespace afterward.



            trimws(toupper(format(begin, "%e-%b-%y")))
            # [1] "1-JAN-17" "1-FEB-17" "1-MAR-17" "1-APR-17" "1-MAY-17" "1-JUN-17"
            # [7] "1-JUL-17" "1-AUG-17" "1-SEP-17" "1-OCT-17" "1-NOV-17" "1-DEC-17"
            # [13] "1-JAN-18" "1-FEB-18" "1-MAR-18" "1-APR-18" "1-MAY-18" "1-JUN-18"
            # [19] "1-JUL-18" "1-AUG-18" "1-SEP-18" "1-OCT-18"


            For the last vector, you can omit trimws because %e won't generate any whitespace for two-digit numbers.



            toupper(format(last, "%e-%b-%y"))
            # [1] "31-JAN-17" "28-FEB-17" "31-MAR-17" "30-APR-17" "31-MAY-17"
            # [6] "30-JUN-17" "31-JUL-17" "31-AUG-17" "30-SEP-17" "31-OCT-17"
            # [11] "30-NOV-17" "31-DEC-17" "31-JAN-18" "28-FEB-18" "31-MAR-18"
            # [16] "30-APR-18" "31-MAY-18" "30-JUN-18" "31-JUL-18" "31-AUG-18"
            # [21] "30-SEP-18" "31-OCT-18" "30-NOV-18"





            share|improve this answer






























              1














              You can use format, wrapping in toupper for upper-case, and trimws to trim the whitespace created by %e. I used %e in format because it is the Day of the month as decimal number (1–31), with a leading space for a single-digit number. So then we just remove the whitespace afterward.



              trimws(toupper(format(begin, "%e-%b-%y")))
              # [1] "1-JAN-17" "1-FEB-17" "1-MAR-17" "1-APR-17" "1-MAY-17" "1-JUN-17"
              # [7] "1-JUL-17" "1-AUG-17" "1-SEP-17" "1-OCT-17" "1-NOV-17" "1-DEC-17"
              # [13] "1-JAN-18" "1-FEB-18" "1-MAR-18" "1-APR-18" "1-MAY-18" "1-JUN-18"
              # [19] "1-JUL-18" "1-AUG-18" "1-SEP-18" "1-OCT-18"


              For the last vector, you can omit trimws because %e won't generate any whitespace for two-digit numbers.



              toupper(format(last, "%e-%b-%y"))
              # [1] "31-JAN-17" "28-FEB-17" "31-MAR-17" "30-APR-17" "31-MAY-17"
              # [6] "30-JUN-17" "31-JUL-17" "31-AUG-17" "30-SEP-17" "31-OCT-17"
              # [11] "30-NOV-17" "31-DEC-17" "31-JAN-18" "28-FEB-18" "31-MAR-18"
              # [16] "30-APR-18" "31-MAY-18" "30-JUN-18" "31-JUL-18" "31-AUG-18"
              # [21] "30-SEP-18" "31-OCT-18" "30-NOV-18"





              share|improve this answer




























                1












                1








                1







                You can use format, wrapping in toupper for upper-case, and trimws to trim the whitespace created by %e. I used %e in format because it is the Day of the month as decimal number (1–31), with a leading space for a single-digit number. So then we just remove the whitespace afterward.



                trimws(toupper(format(begin, "%e-%b-%y")))
                # [1] "1-JAN-17" "1-FEB-17" "1-MAR-17" "1-APR-17" "1-MAY-17" "1-JUN-17"
                # [7] "1-JUL-17" "1-AUG-17" "1-SEP-17" "1-OCT-17" "1-NOV-17" "1-DEC-17"
                # [13] "1-JAN-18" "1-FEB-18" "1-MAR-18" "1-APR-18" "1-MAY-18" "1-JUN-18"
                # [19] "1-JUL-18" "1-AUG-18" "1-SEP-18" "1-OCT-18"


                For the last vector, you can omit trimws because %e won't generate any whitespace for two-digit numbers.



                toupper(format(last, "%e-%b-%y"))
                # [1] "31-JAN-17" "28-FEB-17" "31-MAR-17" "30-APR-17" "31-MAY-17"
                # [6] "30-JUN-17" "31-JUL-17" "31-AUG-17" "30-SEP-17" "31-OCT-17"
                # [11] "30-NOV-17" "31-DEC-17" "31-JAN-18" "28-FEB-18" "31-MAR-18"
                # [16] "30-APR-18" "31-MAY-18" "30-JUN-18" "31-JUL-18" "31-AUG-18"
                # [21] "30-SEP-18" "31-OCT-18" "30-NOV-18"





                share|improve this answer















                You can use format, wrapping in toupper for upper-case, and trimws to trim the whitespace created by %e. I used %e in format because it is the Day of the month as decimal number (1–31), with a leading space for a single-digit number. So then we just remove the whitespace afterward.



                trimws(toupper(format(begin, "%e-%b-%y")))
                # [1] "1-JAN-17" "1-FEB-17" "1-MAR-17" "1-APR-17" "1-MAY-17" "1-JUN-17"
                # [7] "1-JUL-17" "1-AUG-17" "1-SEP-17" "1-OCT-17" "1-NOV-17" "1-DEC-17"
                # [13] "1-JAN-18" "1-FEB-18" "1-MAR-18" "1-APR-18" "1-MAY-18" "1-JUN-18"
                # [19] "1-JUL-18" "1-AUG-18" "1-SEP-18" "1-OCT-18"


                For the last vector, you can omit trimws because %e won't generate any whitespace for two-digit numbers.



                toupper(format(last, "%e-%b-%y"))
                # [1] "31-JAN-17" "28-FEB-17" "31-MAR-17" "30-APR-17" "31-MAY-17"
                # [6] "30-JUN-17" "31-JUL-17" "31-AUG-17" "30-SEP-17" "31-OCT-17"
                # [11] "30-NOV-17" "31-DEC-17" "31-JAN-18" "28-FEB-18" "31-MAR-18"
                # [16] "30-APR-18" "31-MAY-18" "30-JUN-18" "31-JUL-18" "31-AUG-18"
                # [21] "30-SEP-18" "31-OCT-18" "30-NOV-18"






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 21 '18 at 22:16

























                answered Nov 20 '18 at 22:03









                Rich ScrivenRich Scriven

                77k8102172




                77k8102172
































                    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%2f53402224%2fconverting-a-list-of-dates-into-another-format-in-r%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

                    Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                    ComboBox Display Member on multiple fields

                    Is it possible to collect Nectar points via Trainline?