want to know how many days remain of course duration in laravel












0














I want to know that how can I get that how many days are left in course duration.



course-duration is just a column and hold an integer in database like 30.



I want to compare course-duration with created_at and return me that left days in laravel.



id  username  course   course-duration(days)    created_at
---------------------------------------------------------------------
1 krish SSB 14 2018-11-19
---------------------------------------------------------------------
2 Brij SSB 30 2018-11-18
---------------------------------------------------------------------
3 Sagar SSB 90 2018-11-15


I want to get remaining days of the course after comparing course-duration with created_at.










share|improve this question




















  • 2




    I advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 19 '18 at 12:24






  • 1




    share some data, and expected results, and also add some code which you have tried
    – Ahmed Sunny
    Nov 19 '18 at 12:28






  • 1




    SELECT DATE_ADD(created_at, INTERVAL -30 DAY) as date_end FROM your_table;
    – Eakethet
    Nov 19 '18 at 12:31
















0














I want to know that how can I get that how many days are left in course duration.



course-duration is just a column and hold an integer in database like 30.



I want to compare course-duration with created_at and return me that left days in laravel.



id  username  course   course-duration(days)    created_at
---------------------------------------------------------------------
1 krish SSB 14 2018-11-19
---------------------------------------------------------------------
2 Brij SSB 30 2018-11-18
---------------------------------------------------------------------
3 Sagar SSB 90 2018-11-15


I want to get remaining days of the course after comparing course-duration with created_at.










share|improve this question




















  • 2




    I advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 19 '18 at 12:24






  • 1




    share some data, and expected results, and also add some code which you have tried
    – Ahmed Sunny
    Nov 19 '18 at 12:28






  • 1




    SELECT DATE_ADD(created_at, INTERVAL -30 DAY) as date_end FROM your_table;
    – Eakethet
    Nov 19 '18 at 12:31














0












0








0







I want to know that how can I get that how many days are left in course duration.



course-duration is just a column and hold an integer in database like 30.



I want to compare course-duration with created_at and return me that left days in laravel.



id  username  course   course-duration(days)    created_at
---------------------------------------------------------------------
1 krish SSB 14 2018-11-19
---------------------------------------------------------------------
2 Brij SSB 30 2018-11-18
---------------------------------------------------------------------
3 Sagar SSB 90 2018-11-15


I want to get remaining days of the course after comparing course-duration with created_at.










share|improve this question















I want to know that how can I get that how many days are left in course duration.



course-duration is just a column and hold an integer in database like 30.



I want to compare course-duration with created_at and return me that left days in laravel.



id  username  course   course-duration(days)    created_at
---------------------------------------------------------------------
1 krish SSB 14 2018-11-19
---------------------------------------------------------------------
2 Brij SSB 30 2018-11-18
---------------------------------------------------------------------
3 Sagar SSB 90 2018-11-15


I want to get remaining days of the course after comparing course-duration with created_at.







php mysql laravel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 13:01









Znaneswar

2,1442814




2,1442814










asked Nov 19 '18 at 12:23









Krish Bhardwaj

409




409








  • 2




    I advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 19 '18 at 12:24






  • 1




    share some data, and expected results, and also add some code which you have tried
    – Ahmed Sunny
    Nov 19 '18 at 12:28






  • 1




    SELECT DATE_ADD(created_at, INTERVAL -30 DAY) as date_end FROM your_table;
    – Eakethet
    Nov 19 '18 at 12:31














  • 2




    I advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
    – Raymond Nijland
    Nov 19 '18 at 12:24






  • 1




    share some data, and expected results, and also add some code which you have tried
    – Ahmed Sunny
    Nov 19 '18 at 12:28






  • 1




    SELECT DATE_ADD(created_at, INTERVAL -30 DAY) as date_end FROM your_table;
    – Eakethet
    Nov 19 '18 at 12:31








2




2




I advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Raymond Nijland
Nov 19 '18 at 12:24




I advice you to read Why should I provide an MCVE for what seems to me to be a very simple SQL query?
– Raymond Nijland
Nov 19 '18 at 12:24




1




1




share some data, and expected results, and also add some code which you have tried
– Ahmed Sunny
Nov 19 '18 at 12:28




share some data, and expected results, and also add some code which you have tried
– Ahmed Sunny
Nov 19 '18 at 12:28




1




1




SELECT DATE_ADD(created_at, INTERVAL -30 DAY) as date_end FROM your_table;
– Eakethet
Nov 19 '18 at 12:31




SELECT DATE_ADD(created_at, INTERVAL -30 DAY) as date_end FROM your_table;
– Eakethet
Nov 19 '18 at 12:31












4 Answers
4






active

oldest

votes


















1














You can get the remain days like this:



DB::statement("SELECT (course-duration - DATEDIFF(NOW(), created_at)) remained FROM your_table");





share|improve this answer























  • Seems like you have a parentheses too many.
    – Qirel
    Nov 19 '18 at 12:36










  • @Qirel Thank you, has been edited now.
    – ako
    Nov 19 '18 at 12:38



















0














You can use Carbon to get the value of days between created_at and now



$diff_from_now = Carbon::parse($course->created_at)->diffInDays();
$course_duration = $course->duration;
$remaining_days = $course_duration- $diff_from_now;





share|improve this answer























  • In Laravel created_at is an instance of Carbon when retrieved from DB, so there is no need to parse it into a Carbon object again. you can use $course->created_at->diffInDays();.
    – ako
    Nov 19 '18 at 13:38










  • thanks for the note
    – Fahed Aljghine
    Nov 21 '18 at 13:05



















0














Try this one



   Select sub(course-duration - DATE(created_at)) as left_days from table_name;





share|improve this answer





























    0














    Just define a method in your Course model to calculate remaining days of each course:



    class Course extends Model
    {

    public function remainingDays() {
    return $this->course-duration - $this->created_at->diffInDays(Carbon::now());
    }

    }


    And to get remaining days of every course:



    $course->remainingDays();





    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%2f53374562%2fwant-to-know-how-many-days-remain-of-course-duration-in-laravel%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














      You can get the remain days like this:



      DB::statement("SELECT (course-duration - DATEDIFF(NOW(), created_at)) remained FROM your_table");





      share|improve this answer























      • Seems like you have a parentheses too many.
        – Qirel
        Nov 19 '18 at 12:36










      • @Qirel Thank you, has been edited now.
        – ako
        Nov 19 '18 at 12:38
















      1














      You can get the remain days like this:



      DB::statement("SELECT (course-duration - DATEDIFF(NOW(), created_at)) remained FROM your_table");





      share|improve this answer























      • Seems like you have a parentheses too many.
        – Qirel
        Nov 19 '18 at 12:36










      • @Qirel Thank you, has been edited now.
        – ako
        Nov 19 '18 at 12:38














      1












      1








      1






      You can get the remain days like this:



      DB::statement("SELECT (course-duration - DATEDIFF(NOW(), created_at)) remained FROM your_table");





      share|improve this answer














      You can get the remain days like this:



      DB::statement("SELECT (course-duration - DATEDIFF(NOW(), created_at)) remained FROM your_table");






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 19 '18 at 12:42

























      answered Nov 19 '18 at 12:33









      ako

      7731221




      7731221












      • Seems like you have a parentheses too many.
        – Qirel
        Nov 19 '18 at 12:36










      • @Qirel Thank you, has been edited now.
        – ako
        Nov 19 '18 at 12:38


















      • Seems like you have a parentheses too many.
        – Qirel
        Nov 19 '18 at 12:36










      • @Qirel Thank you, has been edited now.
        – ako
        Nov 19 '18 at 12:38
















      Seems like you have a parentheses too many.
      – Qirel
      Nov 19 '18 at 12:36




      Seems like you have a parentheses too many.
      – Qirel
      Nov 19 '18 at 12:36












      @Qirel Thank you, has been edited now.
      – ako
      Nov 19 '18 at 12:38




      @Qirel Thank you, has been edited now.
      – ako
      Nov 19 '18 at 12:38













      0














      You can use Carbon to get the value of days between created_at and now



      $diff_from_now = Carbon::parse($course->created_at)->diffInDays();
      $course_duration = $course->duration;
      $remaining_days = $course_duration- $diff_from_now;





      share|improve this answer























      • In Laravel created_at is an instance of Carbon when retrieved from DB, so there is no need to parse it into a Carbon object again. you can use $course->created_at->diffInDays();.
        – ako
        Nov 19 '18 at 13:38










      • thanks for the note
        – Fahed Aljghine
        Nov 21 '18 at 13:05
















      0














      You can use Carbon to get the value of days between created_at and now



      $diff_from_now = Carbon::parse($course->created_at)->diffInDays();
      $course_duration = $course->duration;
      $remaining_days = $course_duration- $diff_from_now;





      share|improve this answer























      • In Laravel created_at is an instance of Carbon when retrieved from DB, so there is no need to parse it into a Carbon object again. you can use $course->created_at->diffInDays();.
        – ako
        Nov 19 '18 at 13:38










      • thanks for the note
        – Fahed Aljghine
        Nov 21 '18 at 13:05














      0












      0








      0






      You can use Carbon to get the value of days between created_at and now



      $diff_from_now = Carbon::parse($course->created_at)->diffInDays();
      $course_duration = $course->duration;
      $remaining_days = $course_duration- $diff_from_now;





      share|improve this answer














      You can use Carbon to get the value of days between created_at and now



      $diff_from_now = Carbon::parse($course->created_at)->diffInDays();
      $course_duration = $course->duration;
      $remaining_days = $course_duration- $diff_from_now;






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 19 '18 at 13:12









      Wilq

      2,00342332




      2,00342332










      answered Nov 19 '18 at 13:01









      Fahed Aljghine

      263




      263












      • In Laravel created_at is an instance of Carbon when retrieved from DB, so there is no need to parse it into a Carbon object again. you can use $course->created_at->diffInDays();.
        – ako
        Nov 19 '18 at 13:38










      • thanks for the note
        – Fahed Aljghine
        Nov 21 '18 at 13:05


















      • In Laravel created_at is an instance of Carbon when retrieved from DB, so there is no need to parse it into a Carbon object again. you can use $course->created_at->diffInDays();.
        – ako
        Nov 19 '18 at 13:38










      • thanks for the note
        – Fahed Aljghine
        Nov 21 '18 at 13:05
















      In Laravel created_at is an instance of Carbon when retrieved from DB, so there is no need to parse it into a Carbon object again. you can use $course->created_at->diffInDays();.
      – ako
      Nov 19 '18 at 13:38




      In Laravel created_at is an instance of Carbon when retrieved from DB, so there is no need to parse it into a Carbon object again. you can use $course->created_at->diffInDays();.
      – ako
      Nov 19 '18 at 13:38












      thanks for the note
      – Fahed Aljghine
      Nov 21 '18 at 13:05




      thanks for the note
      – Fahed Aljghine
      Nov 21 '18 at 13:05











      0














      Try this one



         Select sub(course-duration - DATE(created_at)) as left_days from table_name;





      share|improve this answer


























        0














        Try this one



           Select sub(course-duration - DATE(created_at)) as left_days from table_name;





        share|improve this answer
























          0












          0








          0






          Try this one



             Select sub(course-duration - DATE(created_at)) as left_days from table_name;





          share|improve this answer












          Try this one



             Select sub(course-duration - DATE(created_at)) as left_days from table_name;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 13:28









          Prashant Deshmukh.....

          44427




          44427























              0














              Just define a method in your Course model to calculate remaining days of each course:



              class Course extends Model
              {

              public function remainingDays() {
              return $this->course-duration - $this->created_at->diffInDays(Carbon::now());
              }

              }


              And to get remaining days of every course:



              $course->remainingDays();





              share|improve this answer


























                0














                Just define a method in your Course model to calculate remaining days of each course:



                class Course extends Model
                {

                public function remainingDays() {
                return $this->course-duration - $this->created_at->diffInDays(Carbon::now());
                }

                }


                And to get remaining days of every course:



                $course->remainingDays();





                share|improve this answer
























                  0












                  0








                  0






                  Just define a method in your Course model to calculate remaining days of each course:



                  class Course extends Model
                  {

                  public function remainingDays() {
                  return $this->course-duration - $this->created_at->diffInDays(Carbon::now());
                  }

                  }


                  And to get remaining days of every course:



                  $course->remainingDays();





                  share|improve this answer












                  Just define a method in your Course model to calculate remaining days of each course:



                  class Course extends Model
                  {

                  public function remainingDays() {
                  return $this->course-duration - $this->created_at->diffInDays(Carbon::now());
                  }

                  }


                  And to get remaining days of every course:



                  $course->remainingDays();






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 '18 at 13:58









                  Pourbahrami

                  1548




                  1548






























                      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%2f53374562%2fwant-to-know-how-many-days-remain-of-course-duration-in-laravel%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

                      Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                      ts Property 'filter' does not exist on type '{}'

                      mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window