want to know how many days remain of course duration in laravel
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
add a comment |
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
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
add a comment |
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
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
edited Nov 19 '18 at 13:01
Znaneswar
2,2142815
2,2142815
asked Nov 19 '18 at 12:23
Krish BhardwajKrish 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
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 '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
add a comment |
4 Answers
4
active
oldest
votes
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 '18 at 12:36
@Qirel Thank you, has been edited now.
– ako
Nov 19 '18 at 12:38
add a comment |
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_at
is an instance ofCarbon
when retrieved from DB, so there is no need to parse it into aCarbon
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
add a comment |
Try this one
Select sub(course-duration - DATE(created_at)) as left_days from table_name;
add a comment |
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 |
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
});
}
});
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
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 '18 at 12:36
@Qirel Thank you, has been edited now.
– ako
Nov 19 '18 at 12:38
add a comment |
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 '18 at 12:36
@Qirel Thank you, has been edited now.
– ako
Nov 19 '18 at 12:38
add a comment |
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 '18 at 12:42
answered Nov 19 '18 at 12:33
akoako
7861321
7861321
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
add a comment |
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
add a comment |
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_at
is an instance ofCarbon
when retrieved from DB, so there is no need to parse it into aCarbon
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
add a comment |
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_at
is an instance ofCarbon
when retrieved from DB, so there is no need to parse it into aCarbon
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
add a comment |
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 '18 at 13:12
Wilq
2,01242432
2,01242432
answered Nov 19 '18 at 13:01
Fahed AljghineFahed Aljghine
263
263
In Laravelcreated_at
is an instance ofCarbon
when retrieved from DB, so there is no need to parse it into aCarbon
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
add a comment |
In Laravelcreated_at
is an instance ofCarbon
when retrieved from DB, so there is no need to parse it into aCarbon
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
add a comment |
Try this one
Select sub(course-duration - DATE(created_at)) as left_days from table_name;
add a comment |
Try this one
Select sub(course-duration - DATE(created_at)) as left_days from table_name;
add a comment |
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 '18 at 13:28
Prashant Deshmukh.....Prashant Deshmukh.....
68658
68658
add a comment |
add a comment |
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 |
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 |
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 '18 at 13:58
PourbahramiPourbahrami
20919
20919
add a comment |
add a comment |
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.
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 '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