Laravel - Getting Current Month and Year only












0














I am new to Laravel I'm just learning new things, but as for my project. I need to get the current month and year for today. How can I do it? for what I have now is a label and I want to put the current month and year on the label. Thank you




Here is my LABEL




{{Form::label('title', 'Title')}}









share|improve this question






















  • How about using jQuery instead of Laravel for month and year?
    – Bonish Koirala
    Nov 20 at 5:07










  • How is it gonna work? can you show me a sample code? thank you
    – Summer Winter
    Nov 20 at 5:09


















0














I am new to Laravel I'm just learning new things, but as for my project. I need to get the current month and year for today. How can I do it? for what I have now is a label and I want to put the current month and year on the label. Thank you




Here is my LABEL




{{Form::label('title', 'Title')}}









share|improve this question






















  • How about using jQuery instead of Laravel for month and year?
    – Bonish Koirala
    Nov 20 at 5:07










  • How is it gonna work? can you show me a sample code? thank you
    – Summer Winter
    Nov 20 at 5:09
















0












0








0







I am new to Laravel I'm just learning new things, but as for my project. I need to get the current month and year for today. How can I do it? for what I have now is a label and I want to put the current month and year on the label. Thank you




Here is my LABEL




{{Form::label('title', 'Title')}}









share|improve this question













I am new to Laravel I'm just learning new things, but as for my project. I need to get the current month and year for today. How can I do it? for what I have now is a label and I want to put the current month and year on the label. Thank you




Here is my LABEL




{{Form::label('title', 'Title')}}






php laravel datetime






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 at 5:06









Summer Winter

1179




1179












  • How about using jQuery instead of Laravel for month and year?
    – Bonish Koirala
    Nov 20 at 5:07










  • How is it gonna work? can you show me a sample code? thank you
    – Summer Winter
    Nov 20 at 5:09




















  • How about using jQuery instead of Laravel for month and year?
    – Bonish Koirala
    Nov 20 at 5:07










  • How is it gonna work? can you show me a sample code? thank you
    – Summer Winter
    Nov 20 at 5:09


















How about using jQuery instead of Laravel for month and year?
– Bonish Koirala
Nov 20 at 5:07




How about using jQuery instead of Laravel for month and year?
– Bonish Koirala
Nov 20 at 5:07












How is it gonna work? can you show me a sample code? thank you
– Summer Winter
Nov 20 at 5:09






How is it gonna work? can you show me a sample code? thank you
– Summer Winter
Nov 20 at 5:09














4 Answers
4






active

oldest

votes


















1














If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.



{{Form::label('title', date('F Y') )}}


See PHP Documentation on the date function



If you want more powerful manipulation, use Carbon.






share|improve this answer



















  • 2




    date('F Y') would work.
    – Sougata Bose
    Nov 20 at 5:18










  • Hey dude, can I save it to database as STRING ?
    – Summer Winter
    Nov 20 at 5:24










  • Of course, date() returns a string.
    – hktang
    Nov 20 at 5:25










  • On the other hand? Can I also save it as DATE?
    – Summer Winter
    Nov 20 at 5:30










  • Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Using date, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
    – hktang
    Nov 20 at 5:33



















2














You can use the Carbon library which is available out of the box with Laravel:



{{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}


You can format using native PHP DateTime Format



Update:



As @Josh mentioned, you can also use the laravel helper now()




The now function creates a new IlluminateSupportCarbon instance for the current time




{{ Form::label('title', now()->format('M, Y') }}





share|improve this answer























  • Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
    – Summer Winter
    Nov 20 at 5:13










  • @SummerWinter add use CarbonCarbon to the top of your file above your class declaration
    – Josh
    Nov 20 at 5:15






  • 1




    Or you can just change it to now()->format('M, Y')
    – Josh
    Nov 20 at 5:15



















2














You can also try this.



{{ Form::label('title', CarbonCarbon::now()->format('F Y') }}





share|improve this answer





























    0














    Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object



    $today = Carbon::now();
    $today->month; // retrieve the month
    $today->year; // retrieve the year of the date


    In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field






    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%2f53386547%2flaravel-getting-current-month-and-year-only%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









      1














      If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.



      {{Form::label('title', date('F Y') )}}


      See PHP Documentation on the date function



      If you want more powerful manipulation, use Carbon.






      share|improve this answer



















      • 2




        date('F Y') would work.
        – Sougata Bose
        Nov 20 at 5:18










      • Hey dude, can I save it to database as STRING ?
        – Summer Winter
        Nov 20 at 5:24










      • Of course, date() returns a string.
        – hktang
        Nov 20 at 5:25










      • On the other hand? Can I also save it as DATE?
        – Summer Winter
        Nov 20 at 5:30










      • Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Using date, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
        – hktang
        Nov 20 at 5:33
















      1














      If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.



      {{Form::label('title', date('F Y') )}}


      See PHP Documentation on the date function



      If you want more powerful manipulation, use Carbon.






      share|improve this answer



















      • 2




        date('F Y') would work.
        – Sougata Bose
        Nov 20 at 5:18










      • Hey dude, can I save it to database as STRING ?
        – Summer Winter
        Nov 20 at 5:24










      • Of course, date() returns a string.
        – hktang
        Nov 20 at 5:25










      • On the other hand? Can I also save it as DATE?
        – Summer Winter
        Nov 20 at 5:30










      • Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Using date, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
        – hktang
        Nov 20 at 5:33














      1












      1








      1






      If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.



      {{Form::label('title', date('F Y') )}}


      See PHP Documentation on the date function



      If you want more powerful manipulation, use Carbon.






      share|improve this answer














      If you want to always display the current day's month and year, you can use PHP's built-in date function. For example, the below will give you a label November 2018.



      {{Form::label('title', date('F Y') )}}


      See PHP Documentation on the date function



      If you want more powerful manipulation, use Carbon.







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 20 at 5:18

























      answered Nov 20 at 5:17









      hktang

      9291329




      9291329








      • 2




        date('F Y') would work.
        – Sougata Bose
        Nov 20 at 5:18










      • Hey dude, can I save it to database as STRING ?
        – Summer Winter
        Nov 20 at 5:24










      • Of course, date() returns a string.
        – hktang
        Nov 20 at 5:25










      • On the other hand? Can I also save it as DATE?
        – Summer Winter
        Nov 20 at 5:30










      • Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Using date, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
        – hktang
        Nov 20 at 5:33














      • 2




        date('F Y') would work.
        – Sougata Bose
        Nov 20 at 5:18










      • Hey dude, can I save it to database as STRING ?
        – Summer Winter
        Nov 20 at 5:24










      • Of course, date() returns a string.
        – hktang
        Nov 20 at 5:25










      • On the other hand? Can I also save it as DATE?
        – Summer Winter
        Nov 20 at 5:30










      • Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Using date, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
        – hktang
        Nov 20 at 5:33








      2




      2




      date('F Y') would work.
      – Sougata Bose
      Nov 20 at 5:18




      date('F Y') would work.
      – Sougata Bose
      Nov 20 at 5:18












      Hey dude, can I save it to database as STRING ?
      – Summer Winter
      Nov 20 at 5:24




      Hey dude, can I save it to database as STRING ?
      – Summer Winter
      Nov 20 at 5:24












      Of course, date() returns a string.
      – hktang
      Nov 20 at 5:25




      Of course, date() returns a string.
      – hktang
      Nov 20 at 5:25












      On the other hand? Can I also save it as DATE?
      – Summer Winter
      Nov 20 at 5:30




      On the other hand? Can I also save it as DATE?
      – Summer Winter
      Nov 20 at 5:30












      Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Using date, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
      – hktang
      Nov 20 at 5:33




      Since you are using Laravel, you might want to check this page for some handy methods of saving dates. laravel.com/docs/5.7/eloquent-mutators#date-mutators. Using date, it's just about formatting your date into the default format: w3schools.com/sql/sql_dates.asp
      – hktang
      Nov 20 at 5:33













      2














      You can use the Carbon library which is available out of the box with Laravel:



      {{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}


      You can format using native PHP DateTime Format



      Update:



      As @Josh mentioned, you can also use the laravel helper now()




      The now function creates a new IlluminateSupportCarbon instance for the current time




      {{ Form::label('title', now()->format('M, Y') }}





      share|improve this answer























      • Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
        – Summer Winter
        Nov 20 at 5:13










      • @SummerWinter add use CarbonCarbon to the top of your file above your class declaration
        – Josh
        Nov 20 at 5:15






      • 1




        Or you can just change it to now()->format('M, Y')
        – Josh
        Nov 20 at 5:15
















      2














      You can use the Carbon library which is available out of the box with Laravel:



      {{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}


      You can format using native PHP DateTime Format



      Update:



      As @Josh mentioned, you can also use the laravel helper now()




      The now function creates a new IlluminateSupportCarbon instance for the current time




      {{ Form::label('title', now()->format('M, Y') }}





      share|improve this answer























      • Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
        – Summer Winter
        Nov 20 at 5:13










      • @SummerWinter add use CarbonCarbon to the top of your file above your class declaration
        – Josh
        Nov 20 at 5:15






      • 1




        Or you can just change it to now()->format('M, Y')
        – Josh
        Nov 20 at 5:15














      2












      2








      2






      You can use the Carbon library which is available out of the box with Laravel:



      {{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}


      You can format using native PHP DateTime Format



      Update:



      As @Josh mentioned, you can also use the laravel helper now()




      The now function creates a new IlluminateSupportCarbon instance for the current time




      {{ Form::label('title', now()->format('M, Y') }}





      share|improve this answer














      You can use the Carbon library which is available out of the box with Laravel:



      {{ Form::label('title', CarbonCarbon::now()->format('M, Y') }}


      You can format using native PHP DateTime Format



      Update:



      As @Josh mentioned, you can also use the laravel helper now()




      The now function creates a new IlluminateSupportCarbon instance for the current time




      {{ Form::label('title', now()->format('M, Y') }}






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 20 at 5:16

























      answered Nov 20 at 5:11









      Angad Dubey

      2,37821634




      2,37821634












      • Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
        – Summer Winter
        Nov 20 at 5:13










      • @SummerWinter add use CarbonCarbon to the top of your file above your class declaration
        – Josh
        Nov 20 at 5:15






      • 1




        Or you can just change it to now()->format('M, Y')
        – Josh
        Nov 20 at 5:15


















      • Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
        – Summer Winter
        Nov 20 at 5:13










      • @SummerWinter add use CarbonCarbon to the top of your file above your class declaration
        – Josh
        Nov 20 at 5:15






      • 1




        Or you can just change it to now()->format('M, Y')
        – Josh
        Nov 20 at 5:15
















      Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
      – Summer Winter
      Nov 20 at 5:13




      Hey dude, I thought it was gonna work but error was found how to solve this one? Class 'Carbon' not found
      – Summer Winter
      Nov 20 at 5:13












      @SummerWinter add use CarbonCarbon to the top of your file above your class declaration
      – Josh
      Nov 20 at 5:15




      @SummerWinter add use CarbonCarbon to the top of your file above your class declaration
      – Josh
      Nov 20 at 5:15




      1




      1




      Or you can just change it to now()->format('M, Y')
      – Josh
      Nov 20 at 5:15




      Or you can just change it to now()->format('M, Y')
      – Josh
      Nov 20 at 5:15











      2














      You can also try this.



      {{ Form::label('title', CarbonCarbon::now()->format('F Y') }}





      share|improve this answer


























        2














        You can also try this.



        {{ Form::label('title', CarbonCarbon::now()->format('F Y') }}





        share|improve this answer
























          2












          2








          2






          You can also try this.



          {{ Form::label('title', CarbonCarbon::now()->format('F Y') }}





          share|improve this answer












          You can also try this.



          {{ Form::label('title', CarbonCarbon::now()->format('F Y') }}






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 4:36









          Sheetal Mehra

          1463




          1463























              0














              Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object



              $today = Carbon::now();
              $today->month; // retrieve the month
              $today->year; // retrieve the year of the date


              In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field






              share|improve this answer




























                0














                Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object



                $today = Carbon::now();
                $today->month; // retrieve the month
                $today->year; // retrieve the year of the date


                In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field






                share|improve this answer


























                  0












                  0








                  0






                  Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object



                  $today = Carbon::now();
                  $today->month; // retrieve the month
                  $today->year; // retrieve the year of the date


                  In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field






                  share|improve this answer














                  Laravel come with a prebuilt component to manage Date, and it's know under the name Carbon it have many method to access and modifie DateTime php object. To access the month and year of the current day you can access the property month and year directly on the Carbon Object



                  $today = Carbon::now();
                  $today->month; // retrieve the month
                  $today->year; // retrieve the year of the date


                  In you Controller you can pas the $today object to the method use to render the related view with purpose to have access to that object on a get value of attribute that you want to show in the label field







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 20 at 5:34

























                  answered Nov 20 at 5:28









                  Yves Kipondo

                  1,338414




                  1,338414






























                      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%2f53386547%2flaravel-getting-current-month-and-year-only%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

                      "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                      Alcedinidae

                      RAC Tourist Trophy