Next Augustus in Future with Carbon












0















Is there prettier way to get the full-date of the next 1st of August:



$year = date('Y') + 1;
if (date('j') >= 1 && date('j') <= 8) {
$year = date('Y');
}
$nextAugust = '01-08-' . $year;
$nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);


Preferably with Carbon PHP










share|improve this question



























    0















    Is there prettier way to get the full-date of the next 1st of August:



    $year = date('Y') + 1;
    if (date('j') >= 1 && date('j') <= 8) {
    $year = date('Y');
    }
    $nextAugust = '01-08-' . $year;
    $nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);


    Preferably with Carbon PHP










    share|improve this question

























      0












      0








      0


      1






      Is there prettier way to get the full-date of the next 1st of August:



      $year = date('Y') + 1;
      if (date('j') >= 1 && date('j') <= 8) {
      $year = date('Y');
      }
      $nextAugust = '01-08-' . $year;
      $nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);


      Preferably with Carbon PHP










      share|improve this question














      Is there prettier way to get the full-date of the next 1st of August:



      $year = date('Y') + 1;
      if (date('j') >= 1 && date('j') <= 8) {
      $year = date('Y');
      }
      $nextAugust = '01-08-' . $year;
      $nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);


      Preferably with Carbon PHP







      php-carbon






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 12:29









      user1469734user1469734

      92552741




      92552741
























          3 Answers
          3






          active

          oldest

          votes


















          1





          +50









          Following code find next august with carbon object.



          $nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));


          I hope my answer can help for your problem.






          share|improve this answer































            0














            This will do it:



            $nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));


            Clarification:



            Instead of the if condition, you can divide the current month by 8 and convert the resulting value to an integer using intval(date('m') / 8). This will give you either 0 or 1, and will be added to the current year. For example, if you are in March (i.e., m is 3), you get 3/8 = 0. Hence, next August will be in the same year because 2018 + 0 will be 2018. On the other hand, if you are in October (i.e., m is 10), you get 10/8 = 1. Hence, next August will be in the next year because 2018 + 1 will be 2019. Here's how you simply implement it:



            Hope it helps.






            share|improve this answer


























            • What does the intval(date('m') / 8) do? I meant more like: Carbon::parse('next August'), but that doesn't work..

              – user1469734
              Nov 29 '18 at 8:57











            • @user1469734 I updated my answer to clarify this.

              – TeeKea
              Nov 29 '18 at 15:38



















            -2














            For me, I'll do:



            $date = '01-08-';
            $year_now = Carbon::now()->format('Y');
            $date = $date.$year_now;
            $carbon_date = Carbon::createFromFormat('d-m-Y', $date);


            Let me know if it is not working.






            share|improve this answer
























            • Can't take this seriously

              – user1469734
              Nov 29 '18 at 8:56











            • Are you trolling?

              – user1670816
              Nov 29 '18 at 10:28











            Your Answer






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

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

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

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


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393018%2fnext-augustus-in-future-with-carbon%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1





            +50









            Following code find next august with carbon object.



            $nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));


            I hope my answer can help for your problem.






            share|improve this answer




























              1





              +50









              Following code find next august with carbon object.



              $nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));


              I hope my answer can help for your problem.






              share|improve this answer


























                1





                +50







                1





                +50



                1




                +50





                Following code find next august with carbon object.



                $nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));


                I hope my answer can help for your problem.






                share|improve this answer













                Following code find next august with carbon object.



                $nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));


                I hope my answer can help for your problem.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 29 '18 at 14:39









                FGDeveloperFGDeveloper

                664415




                664415

























                    0














                    This will do it:



                    $nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));


                    Clarification:



                    Instead of the if condition, you can divide the current month by 8 and convert the resulting value to an integer using intval(date('m') / 8). This will give you either 0 or 1, and will be added to the current year. For example, if you are in March (i.e., m is 3), you get 3/8 = 0. Hence, next August will be in the same year because 2018 + 0 will be 2018. On the other hand, if you are in October (i.e., m is 10), you get 10/8 = 1. Hence, next August will be in the next year because 2018 + 1 will be 2019. Here's how you simply implement it:



                    Hope it helps.






                    share|improve this answer


























                    • What does the intval(date('m') / 8) do? I meant more like: Carbon::parse('next August'), but that doesn't work..

                      – user1469734
                      Nov 29 '18 at 8:57











                    • @user1469734 I updated my answer to clarify this.

                      – TeeKea
                      Nov 29 '18 at 15:38
















                    0














                    This will do it:



                    $nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));


                    Clarification:



                    Instead of the if condition, you can divide the current month by 8 and convert the resulting value to an integer using intval(date('m') / 8). This will give you either 0 or 1, and will be added to the current year. For example, if you are in March (i.e., m is 3), you get 3/8 = 0. Hence, next August will be in the same year because 2018 + 0 will be 2018. On the other hand, if you are in October (i.e., m is 10), you get 10/8 = 1. Hence, next August will be in the next year because 2018 + 1 will be 2019. Here's how you simply implement it:



                    Hope it helps.






                    share|improve this answer


























                    • What does the intval(date('m') / 8) do? I meant more like: Carbon::parse('next August'), but that doesn't work..

                      – user1469734
                      Nov 29 '18 at 8:57











                    • @user1469734 I updated my answer to clarify this.

                      – TeeKea
                      Nov 29 '18 at 15:38














                    0












                    0








                    0







                    This will do it:



                    $nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));


                    Clarification:



                    Instead of the if condition, you can divide the current month by 8 and convert the resulting value to an integer using intval(date('m') / 8). This will give you either 0 or 1, and will be added to the current year. For example, if you are in March (i.e., m is 3), you get 3/8 = 0. Hence, next August will be in the same year because 2018 + 0 will be 2018. On the other hand, if you are in October (i.e., m is 10), you get 10/8 = 1. Hence, next August will be in the next year because 2018 + 1 will be 2019. Here's how you simply implement it:



                    Hope it helps.






                    share|improve this answer















                    This will do it:



                    $nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));


                    Clarification:



                    Instead of the if condition, you can divide the current month by 8 and convert the resulting value to an integer using intval(date('m') / 8). This will give you either 0 or 1, and will be added to the current year. For example, if you are in March (i.e., m is 3), you get 3/8 = 0. Hence, next August will be in the same year because 2018 + 0 will be 2018. On the other hand, if you are in October (i.e., m is 10), you get 10/8 = 1. Hence, next August will be in the next year because 2018 + 1 will be 2019. Here's how you simply implement it:



                    Hope it helps.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 29 '18 at 16:49

























                    answered Nov 29 '18 at 5:26









                    TeeKeaTeeKea

                    3,22341630




                    3,22341630













                    • What does the intval(date('m') / 8) do? I meant more like: Carbon::parse('next August'), but that doesn't work..

                      – user1469734
                      Nov 29 '18 at 8:57











                    • @user1469734 I updated my answer to clarify this.

                      – TeeKea
                      Nov 29 '18 at 15:38



















                    • What does the intval(date('m') / 8) do? I meant more like: Carbon::parse('next August'), but that doesn't work..

                      – user1469734
                      Nov 29 '18 at 8:57











                    • @user1469734 I updated my answer to clarify this.

                      – TeeKea
                      Nov 29 '18 at 15:38

















                    What does the intval(date('m') / 8) do? I meant more like: Carbon::parse('next August'), but that doesn't work..

                    – user1469734
                    Nov 29 '18 at 8:57





                    What does the intval(date('m') / 8) do? I meant more like: Carbon::parse('next August'), but that doesn't work..

                    – user1469734
                    Nov 29 '18 at 8:57













                    @user1469734 I updated my answer to clarify this.

                    – TeeKea
                    Nov 29 '18 at 15:38





                    @user1469734 I updated my answer to clarify this.

                    – TeeKea
                    Nov 29 '18 at 15:38











                    -2














                    For me, I'll do:



                    $date = '01-08-';
                    $year_now = Carbon::now()->format('Y');
                    $date = $date.$year_now;
                    $carbon_date = Carbon::createFromFormat('d-m-Y', $date);


                    Let me know if it is not working.






                    share|improve this answer
























                    • Can't take this seriously

                      – user1469734
                      Nov 29 '18 at 8:56











                    • Are you trolling?

                      – user1670816
                      Nov 29 '18 at 10:28
















                    -2














                    For me, I'll do:



                    $date = '01-08-';
                    $year_now = Carbon::now()->format('Y');
                    $date = $date.$year_now;
                    $carbon_date = Carbon::createFromFormat('d-m-Y', $date);


                    Let me know if it is not working.






                    share|improve this answer
























                    • Can't take this seriously

                      – user1469734
                      Nov 29 '18 at 8:56











                    • Are you trolling?

                      – user1670816
                      Nov 29 '18 at 10:28














                    -2












                    -2








                    -2







                    For me, I'll do:



                    $date = '01-08-';
                    $year_now = Carbon::now()->format('Y');
                    $date = $date.$year_now;
                    $carbon_date = Carbon::createFromFormat('d-m-Y', $date);


                    Let me know if it is not working.






                    share|improve this answer













                    For me, I'll do:



                    $date = '01-08-';
                    $year_now = Carbon::now()->format('Y');
                    $date = $date.$year_now;
                    $carbon_date = Carbon::createFromFormat('d-m-Y', $date);


                    Let me know if it is not working.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 29 '18 at 5:17









                    ChrisChris

                    11




                    11













                    • Can't take this seriously

                      – user1469734
                      Nov 29 '18 at 8:56











                    • Are you trolling?

                      – user1670816
                      Nov 29 '18 at 10:28



















                    • Can't take this seriously

                      – user1469734
                      Nov 29 '18 at 8:56











                    • Are you trolling?

                      – user1670816
                      Nov 29 '18 at 10:28

















                    Can't take this seriously

                    – user1469734
                    Nov 29 '18 at 8:56





                    Can't take this seriously

                    – user1469734
                    Nov 29 '18 at 8:56













                    Are you trolling?

                    – user1670816
                    Nov 29 '18 at 10:28





                    Are you trolling?

                    – user1670816
                    Nov 29 '18 at 10:28


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


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

                    But avoid



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

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


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




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393018%2fnext-augustus-in-future-with-carbon%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

                    MongoDB - Not Authorized To Execute Command

                    in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

                    How to fix TextFormField cause rebuild widget in Flutter