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











up vote
0
down vote

favorite












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









New contributor




Krish Bhardwaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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 at 12:24






  • 1




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






  • 1




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















up vote
0
down vote

favorite












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









New contributor




Krish Bhardwaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
















  • 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 at 12:24






  • 1




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






  • 1




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













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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









New contributor




Krish Bhardwaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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









New contributor




Krish Bhardwaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Krish Bhardwaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 19 at 13:01









Znaneswar

2,1262813




2,1262813






New contributor




Krish Bhardwaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 19 at 12:23









Krish Bhardwaj

218




218




New contributor




Krish Bhardwaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Krish Bhardwaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Krish Bhardwaj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








  • 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 at 12:24






  • 1




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






  • 1




    SELECT DATE_ADD(created_at, INTERVAL -30 DAY) as date_end FROM your_table;
    – Eakethet
    Nov 19 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 at 12:24






  • 1




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






  • 1




    SELECT DATE_ADD(created_at, INTERVAL -30 DAY) as date_end FROM your_table;
    – Eakethet
    Nov 19 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 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 at 12:24




1




1




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




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




1




1




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




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












4 Answers
4






active

oldest

votes

















up vote
1
down vote













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 at 12:36










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


















up vote
0
down vote













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 at 13:38










  • thanks for the note
    – Fahed Aljghine
    2 days ago


















up vote
0
down vote













Try this one



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





share|improve this answer




























    up vote
    0
    down vote













    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',
      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
      });


      }
      });






      Krish Bhardwaj is a new contributor. Be nice, and check out our Code of Conduct.










       

      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








      up vote
      1
      down vote













      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 at 12:36










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















      up vote
      1
      down vote













      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 at 12:36










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













      up vote
      1
      down vote










      up vote
      1
      down vote









      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 at 12:42

























      answered Nov 19 at 12:33









      ako

      7181121




      7181121












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










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


















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










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
















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




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












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




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












      up vote
      0
      down vote













      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 at 13:38










      • thanks for the note
        – Fahed Aljghine
        2 days ago















      up vote
      0
      down vote













      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 at 13:38










      • thanks for the note
        – Fahed Aljghine
        2 days ago













      up vote
      0
      down vote










      up vote
      0
      down vote









      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 at 13:12









      Wilq

      2,00242332




      2,00242332










      answered Nov 19 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 at 13:38










      • thanks for the note
        – Fahed Aljghine
        2 days ago


















      • 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 at 13:38










      • thanks for the note
        – Fahed Aljghine
        2 days ago
















      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 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 at 13:38












      thanks for the note
      – Fahed Aljghine
      2 days ago




      thanks for the note
      – Fahed Aljghine
      2 days ago










      up vote
      0
      down vote













      Try this one



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





      share|improve this answer

























        up vote
        0
        down vote













        Try this one



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





        share|improve this answer























          up vote
          0
          down vote










          up vote
          0
          down vote









          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 at 13:28









          Prashant Deshmukh.....

          717




          717






















              up vote
              0
              down vote













              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

























                up vote
                0
                down vote













                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























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  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 at 13:58









                  Pourbahrami

                  1448




                  1448






















                      Krish Bhardwaj is a new contributor. Be nice, and check out our Code of Conduct.










                       

                      draft saved


                      draft discarded


















                      Krish Bhardwaj is a new contributor. Be nice, and check out our Code of Conduct.













                      Krish Bhardwaj is a new contributor. Be nice, and check out our Code of Conduct.












                      Krish Bhardwaj is a new contributor. Be nice, and check out our Code of Conduct.















                       


                      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

                      Tonle Sap (See)

                      I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                      Guatemaltekische Davis-Cup-Mannschaft