-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug in subMonth #639
Comments
same issue here Carbon::now('Europe/Berlin')-toDateTimeString() => 2016-03-30 20:11:31 Workaround: Carbon::now()->startOfMonth()->subSecond()->startOfMonth() => 2016-02-01 00:00:00 regards |
I met the same question today is 2016/3/31 $startTime = new Carbon('this month first day') // echo 2016-04-01 $now = Carbon::createFromDate(2016, 3, 1);
$last3Month = $now->subMonth(3);
$last2Month = $now->subMonth(2);
$lastMonth = $now->subMonth(1);
Carbon\Carbon Object
(
[date] => 2015-09-01 16:17:30.000000
[timezone_type] => 3
[timezone] => Etc/GMT-8
)
Carbon\Carbon Object
(
[date] => 2015-09-01 16:17:30.000000
[timezone_type] => 3
[timezone] => Etc/GMT-8
)
Carbon\Carbon Object
(
[date] => 2015-09-01 16:17:30.000000
[timezone_type] => 3
[timezone] => Etc/GMT-8
) |
Experiencing the same issue here. It happens with It appears the bug lies with php's A simple workaround to avoid this: $nextMonth = (new Carbon($date))->endOfMonth()->addDay()->startOfDay();
$prevMonth = (new Carbon($date))->startOfMonth()->subDay()->endOfDay(); |
I think the problem is deeper than this as I am having issues with even creating the correct object. Carbon::createFromFormat('Y-m', '2016-02');
// or
Carbon::create(2016, 2, null, null, null, null, 'Europe/London'); The above returns an object of 2016-03-02; Adding the first day of the month fixes the issue. Carbon::create(2016, 2, 1, null, null, null, 'Europe/London'); |
Everyone, |
Can it be closed @cmachu ? |
Yeap, thanks ! |
what i fixed it by add "->subDay(3)",becaue february is 2-3 days less than other months. |
Don't do that, if you're january the 1st, then you will get the end of november. Simply do: |
Code:
return:
for other months work correctly.
The text was updated successfully, but these errors were encountered: