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.
php mysql laravel
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.
add a comment |
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.
php mysql laravel
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
add a comment |
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.
php mysql laravel
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
php mysql laravel
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.
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
add a comment |
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
add a comment |
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");
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
add a comment |
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;
In Laravelcreated_atis an instance ofCarbonwhen retrieved from DB, so there is no need to parse it into aCarbonobject again. you can use$course->created_at->diffInDays();.
– ako
Nov 19 at 13:38
thanks for the note
– Fahed Aljghine
2 days ago
add a comment |
up vote
0
down vote
Try this one
Select sub(course-duration - DATE(created_at)) as left_days from table_name;
add a comment |
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();
add a comment |
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");
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
add a comment |
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");
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
add a comment |
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");
You can get the remain days like this:
DB::statement("SELECT (course-duration - DATEDIFF(NOW(), created_at)) remained FROM your_table");
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
add a comment |
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
add a comment |
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;
In Laravelcreated_atis an instance ofCarbonwhen retrieved from DB, so there is no need to parse it into aCarbonobject again. you can use$course->created_at->diffInDays();.
– ako
Nov 19 at 13:38
thanks for the note
– Fahed Aljghine
2 days ago
add a comment |
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;
In Laravelcreated_atis an instance ofCarbonwhen retrieved from DB, so there is no need to parse it into aCarbonobject again. you can use$course->created_at->diffInDays();.
– ako
Nov 19 at 13:38
thanks for the note
– Fahed Aljghine
2 days ago
add a comment |
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;
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;
edited Nov 19 at 13:12
Wilq
2,00242332
2,00242332
answered Nov 19 at 13:01
Fahed Aljghine
263
263
In Laravelcreated_atis an instance ofCarbonwhen retrieved from DB, so there is no need to parse it into aCarbonobject again. you can use$course->created_at->diffInDays();.
– ako
Nov 19 at 13:38
thanks for the note
– Fahed Aljghine
2 days ago
add a comment |
In Laravelcreated_atis an instance ofCarbonwhen retrieved from DB, so there is no need to parse it into aCarbonobject 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
add a comment |
up vote
0
down vote
Try this one
Select sub(course-duration - DATE(created_at)) as left_days from table_name;
add a comment |
up vote
0
down vote
Try this one
Select sub(course-duration - DATE(created_at)) as left_days from table_name;
add a comment |
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;
Try this one
Select sub(course-duration - DATE(created_at)) as left_days from table_name;
answered Nov 19 at 13:28
Prashant Deshmukh.....
717
717
add a comment |
add a comment |
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();
add a comment |
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();
add a comment |
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();
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();
answered Nov 19 at 13:58
Pourbahrami
1448
1448
add a comment |
add a comment |
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.
Krish Bhardwaj is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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