1,486 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
1
answer
55
views
Split CarbonPeriod into days (PHP)
I have this CarbonPeriod with start 2025年06月09日 19:00 and end 2025年06月11日 11:00. What I want is an array of the days with start and end date. So basicly an array like this, possibly with new ...
1
vote
2
answers
78
views
How to Carbon value to add other time field?
In laravel 10 / php 8.2 time I have a time field and in model I have defined cast:
<?php
namespace App\Casts;
use Carbon\Carbon;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use ...
-1
votes
1
answer
86
views
Getting time from string with Carbon method I got error
On Laravel 11 site with php 8.3
I need to get only time(hours/minutes) from request time field with value
[time] => 2025年03月18日T07:23:16.000Z
So I need result must be 07:23
I try to use ...
1
vote
2
answers
277
views
PHP Carbon diffInWeekdays alternative to return float instead of int
I'm working on a leave/holiday management system.
As well as booking full days leave/holiday they can book half days (morning or afternoon off).
I need to calculate the total amount of days during a ...
1
vote
2
answers
427
views
Carbon diffInSeconds() returning negative value
I recently updated nesbot/Carbon from 2.67 to 3.8.6. When running the following piece of code, I used to get a positive value, now I get a negative value. Has the order of operation changed for ...
0
votes
1
answer
74
views
CarbonPeriod returns duplicate week month [duplicate]
I am formatting the dates of all weeks in a date range that exceeds 1 year using CarbonPeriod:
$period = CarbonPeriod::create('2024-01-01', '1 week', '2025-01-31');
foreach ($period as $date) {
...
0
votes
1
answer
332
views
Carbon macro not validated by PHPStan
I'm registering a custom Carbon macro in my Laravel's AppServiceProvider
Carbon::macro('itFormat', static function () {
return ucwords(self::this()->translatedFormat('l d/m/Y'));
});
But ...
0
votes
1
answer
69
views
Discrepancy between ->created_at and ->value('created_at') in Laravel: Why do they return different values?
I'm facing an issue in my Laravel 10 application where accessing the created_at attribute directly from a model instance returns a different value than when using the value() method on the same model.
...
3
votes
1
answer
355
views
Why does Carbon::createFromFormat() not throw an exception when given a UK format and a US date?
I have this code:
try {
Carbon::createFromFormat('dmY', $rawDate)->format('Ymd');
} catch (InvalidFormatException $e) {
echo 'Oops, bad date format.';
}
If I feed in 31012024 as my $...
-1
votes
1
answer
146
views
Using a custom MariaDb Grammar for Carbon timestamp precision with Laravel, the application crashes when calling `$builder->toRawSql()`
My goal is to store microseconds in a MariaDB database timestamp fields when using a laravel application.
Following the instructions on https://carbon.nesbot.com/laravel/, I created my Grammar class:
...
0
votes
2
answers
193
views
How can I use Carbon::setTestNow() to influence the results of the FakerPHP dateTimeBetween method?
I'm using model factory methods in my Laravel test suite that return date ranges. For instance:
class WorkSiteFactory extends Factory
{
// ... Other factory stuff....
/**
* Indicate that the ...
1
vote
1
answer
118
views
Issue when casting to datetime format in Laravel
I'm having an issue with timestamps in my Laravel app. Our database stores timestamps in CEST, but when I cast them to a datetime object, Laravel automatically converts them to UTC, even though my ...
1
vote
1
answer
65
views
Why formatted date with carbon is invalid?
Why in In laravel 11, PHP 8.2 app running code
$minDay = CurrencyHistory::select(DB::raw('MIN(day) as min_day'))->first()->min_day;
\Log::info($minDay);
\Log::info(Carbon::createFromTimestamp(...
0
votes
2
answers
116
views
Carbon and PHP DateTime parse single letters as dates, but not multi-character strings
While using the nesbot/carbon library I've noticed that it accepts single letters as valid dates and parses them in a way that maps to a relative time range. Specifically, single letters are parsed (...
0
votes
2
answers
43
views
With Nesbot Carbon diffForHumans(), display 19 months instead of 1 year when less than 26 months
I display a diffForHumans with one part
echo Carbon::create('1 hour 59 minutes ago')->diffForHumans(); // 1 hour ago
echo Carbon::create('1 day 23 hours ago')->diffForHumans(); // 1 day ago
echo ...