Next Augustus in Future with Carbon
Is there prettier way to get the full-date of the next 1st of August:
$year = date('Y') + 1;
if (date('j') >= 1 && date('j') <= 8) {
$year = date('Y');
}
$nextAugust = '01-08-' . $year;
$nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);
Preferably with Carbon PHP
php-carbon
add a comment |
Is there prettier way to get the full-date of the next 1st of August:
$year = date('Y') + 1;
if (date('j') >= 1 && date('j') <= 8) {
$year = date('Y');
}
$nextAugust = '01-08-' . $year;
$nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);
Preferably with Carbon PHP
php-carbon
add a comment |
Is there prettier way to get the full-date of the next 1st of August:
$year = date('Y') + 1;
if (date('j') >= 1 && date('j') <= 8) {
$year = date('Y');
}
$nextAugust = '01-08-' . $year;
$nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);
Preferably with Carbon PHP
php-carbon
Is there prettier way to get the full-date of the next 1st of August:
$year = date('Y') + 1;
if (date('j') >= 1 && date('j') <= 8) {
$year = date('Y');
}
$nextAugust = '01-08-' . $year;
$nextAugust = Carbon::createFromFormat('d-m-Y', $nextAugust);
Preferably with Carbon PHP
php-carbon
php-carbon
asked Nov 20 '18 at 12:29
user1469734user1469734
92552741
92552741
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Following code find next august with carbon object.
$nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));
I hope my answer can help for your problem.
add a comment |
This will do it:
$nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));
Clarification:
Instead of the if
condition, you can divide the current month by 8
and convert the resulting value to an integer using intval(date('m') / 8)
. This will give you either 0
or 1
, and will be added to the current year. For example, if you are in March (i.e., m
is 3
), you get 3/8
= 0
. Hence, next August will be in the same year because 2018 + 0
will be 2018
. On the other hand, if you are in October (i.e., m
is 10
), you get 10/8
= 1
. Hence, next August will be in the next year because 2018 + 1
will be 2019
. Here's how you simply implement it:
Hope it helps.
What does the intval(date('m') / 8) do? I meant more like:Carbon::parse('next August')
, but that doesn't work..
– user1469734
Nov 29 '18 at 8:57
@user1469734 I updated my answer to clarify this.
– TeeKea
Nov 29 '18 at 15:38
add a comment |
For me, I'll do:
$date = '01-08-';
$year_now = Carbon::now()->format('Y');
$date = $date.$year_now;
$carbon_date = Carbon::createFromFormat('d-m-Y', $date);
Let me know if it is not working.
Can't take this seriously
– user1469734
Nov 29 '18 at 8:56
Are you trolling?
– user1670816
Nov 29 '18 at 10:28
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%2f53393018%2fnext-augustus-in-future-with-carbon%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Following code find next august with carbon object.
$nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));
I hope my answer can help for your problem.
add a comment |
Following code find next august with carbon object.
$nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));
I hope my answer can help for your problem.
add a comment |
Following code find next august with carbon object.
$nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));
I hope my answer can help for your problem.
Following code find next august with carbon object.
$nextAugust = Carbon::parse('first day of August' . (date('n') > 8 ? ' next year' : ''));
I hope my answer can help for your problem.
answered Nov 29 '18 at 14:39


FGDeveloperFGDeveloper
664415
664415
add a comment |
add a comment |
This will do it:
$nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));
Clarification:
Instead of the if
condition, you can divide the current month by 8
and convert the resulting value to an integer using intval(date('m') / 8)
. This will give you either 0
or 1
, and will be added to the current year. For example, if you are in March (i.e., m
is 3
), you get 3/8
= 0
. Hence, next August will be in the same year because 2018 + 0
will be 2018
. On the other hand, if you are in October (i.e., m
is 10
), you get 10/8
= 1
. Hence, next August will be in the next year because 2018 + 1
will be 2019
. Here's how you simply implement it:
Hope it helps.
What does the intval(date('m') / 8) do? I meant more like:Carbon::parse('next August')
, but that doesn't work..
– user1469734
Nov 29 '18 at 8:57
@user1469734 I updated my answer to clarify this.
– TeeKea
Nov 29 '18 at 15:38
add a comment |
This will do it:
$nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));
Clarification:
Instead of the if
condition, you can divide the current month by 8
and convert the resulting value to an integer using intval(date('m') / 8)
. This will give you either 0
or 1
, and will be added to the current year. For example, if you are in March (i.e., m
is 3
), you get 3/8
= 0
. Hence, next August will be in the same year because 2018 + 0
will be 2018
. On the other hand, if you are in October (i.e., m
is 10
), you get 10/8
= 1
. Hence, next August will be in the next year because 2018 + 1
will be 2019
. Here's how you simply implement it:
Hope it helps.
What does the intval(date('m') / 8) do? I meant more like:Carbon::parse('next August')
, but that doesn't work..
– user1469734
Nov 29 '18 at 8:57
@user1469734 I updated my answer to clarify this.
– TeeKea
Nov 29 '18 at 15:38
add a comment |
This will do it:
$nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));
Clarification:
Instead of the if
condition, you can divide the current month by 8
and convert the resulting value to an integer using intval(date('m') / 8)
. This will give you either 0
or 1
, and will be added to the current year. For example, if you are in March (i.e., m
is 3
), you get 3/8
= 0
. Hence, next August will be in the same year because 2018 + 0
will be 2018
. On the other hand, if you are in October (i.e., m
is 10
), you get 10/8
= 1
. Hence, next August will be in the next year because 2018 + 1
will be 2019
. Here's how you simply implement it:
Hope it helps.
This will do it:
$nextAugust = Carbon::createFromFormat('d-m-Y', '01-08-' . (date('Y') + intval(date('m') / 8)));
Clarification:
Instead of the if
condition, you can divide the current month by 8
and convert the resulting value to an integer using intval(date('m') / 8)
. This will give you either 0
or 1
, and will be added to the current year. For example, if you are in March (i.e., m
is 3
), you get 3/8
= 0
. Hence, next August will be in the same year because 2018 + 0
will be 2018
. On the other hand, if you are in October (i.e., m
is 10
), you get 10/8
= 1
. Hence, next August will be in the next year because 2018 + 1
will be 2019
. Here's how you simply implement it:
Hope it helps.
edited Nov 29 '18 at 16:49
answered Nov 29 '18 at 5:26


TeeKeaTeeKea
3,22341630
3,22341630
What does the intval(date('m') / 8) do? I meant more like:Carbon::parse('next August')
, but that doesn't work..
– user1469734
Nov 29 '18 at 8:57
@user1469734 I updated my answer to clarify this.
– TeeKea
Nov 29 '18 at 15:38
add a comment |
What does the intval(date('m') / 8) do? I meant more like:Carbon::parse('next August')
, but that doesn't work..
– user1469734
Nov 29 '18 at 8:57
@user1469734 I updated my answer to clarify this.
– TeeKea
Nov 29 '18 at 15:38
What does the intval(date('m') / 8) do? I meant more like:
Carbon::parse('next August')
, but that doesn't work..– user1469734
Nov 29 '18 at 8:57
What does the intval(date('m') / 8) do? I meant more like:
Carbon::parse('next August')
, but that doesn't work..– user1469734
Nov 29 '18 at 8:57
@user1469734 I updated my answer to clarify this.
– TeeKea
Nov 29 '18 at 15:38
@user1469734 I updated my answer to clarify this.
– TeeKea
Nov 29 '18 at 15:38
add a comment |
For me, I'll do:
$date = '01-08-';
$year_now = Carbon::now()->format('Y');
$date = $date.$year_now;
$carbon_date = Carbon::createFromFormat('d-m-Y', $date);
Let me know if it is not working.
Can't take this seriously
– user1469734
Nov 29 '18 at 8:56
Are you trolling?
– user1670816
Nov 29 '18 at 10:28
add a comment |
For me, I'll do:
$date = '01-08-';
$year_now = Carbon::now()->format('Y');
$date = $date.$year_now;
$carbon_date = Carbon::createFromFormat('d-m-Y', $date);
Let me know if it is not working.
Can't take this seriously
– user1469734
Nov 29 '18 at 8:56
Are you trolling?
– user1670816
Nov 29 '18 at 10:28
add a comment |
For me, I'll do:
$date = '01-08-';
$year_now = Carbon::now()->format('Y');
$date = $date.$year_now;
$carbon_date = Carbon::createFromFormat('d-m-Y', $date);
Let me know if it is not working.
For me, I'll do:
$date = '01-08-';
$year_now = Carbon::now()->format('Y');
$date = $date.$year_now;
$carbon_date = Carbon::createFromFormat('d-m-Y', $date);
Let me know if it is not working.
answered Nov 29 '18 at 5:17
ChrisChris
11
11
Can't take this seriously
– user1469734
Nov 29 '18 at 8:56
Are you trolling?
– user1670816
Nov 29 '18 at 10:28
add a comment |
Can't take this seriously
– user1469734
Nov 29 '18 at 8:56
Are you trolling?
– user1670816
Nov 29 '18 at 10:28
Can't take this seriously
– user1469734
Nov 29 '18 at 8:56
Can't take this seriously
– user1469734
Nov 29 '18 at 8:56
Are you trolling?
– user1670816
Nov 29 '18 at 10:28
Are you trolling?
– user1670816
Nov 29 '18 at 10:28
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%2f53393018%2fnext-augustus-in-future-with-carbon%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