Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Carbon::createFromFormat fails: separation symbol not found, trailing data or not enough data

Your error

Carbon\Exceptions\InvalidFormatException: The separation symbol could not be found3 more lines it can show

Fix it fast

Most common cause, 1 of 3

The separators or the order in the format differ from the input

Write the format the way the input really arrives, and reject other shapes in validation before parsing.

Fix
$request->validate([
    'starts_on' => ['required', 'date_format:d/m/Y'],
]);

$startsOn = Carbon::createFromFormat('!d/m/Y', $request->input('starts_on'));
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

"The separation symbol could not be found", "Trailing data" and "Not enough data available to satisfy format" come from PHP's date parser, rethrown by Carbon 3 as InvalidFormatException. The createFromFormat format does not match the string: other separators or order, extra text such as a time, or missing parts. Write the format for the exact input and validate with date_format.

  • Applies to Carbon 3, Laravel 13, PHP 8.4 and 8.5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Run the same format and string through PHP's own parser and print its error list. Each entry is keyed by the character position where parsing stopped, which shows the exact spot the format and the input part ways.

Run this first
php artisan tinker --execute="DateTimeImmutable::createFromFormat('Y-m-d', '21/11/2026'); dump(DateTimeImmutable::getLastErrors());"

Then find the line you see in this list and open its fix:

  1. 1The separators or the order in the format differ from the inputThe separation symbol could not be found, or A two digit month could not be found, at a low position in the string
  2. 2The input carries more than the format describesTrailing data, with the position pointing just after the part the format covers
  3. 3The input is shorter than the formatNot enough data available to satisfy format (worded Data missing before PHP 8.1)

What does the error look like?

  • Carbon\Exceptions\InvalidFormatException: The separation symbol could not be found
  • Carbon\Exceptions\InvalidFormatException: Trailing data
  • Not enough data available to satisfy format
  • A two digit month could not be found

Cause 1 of 3

The separators or the order in the format differ from the input

You seeThe separation symbol could not be found, or A two digit month could not be found, at a low position in the string

Check

The separation symbol could not be found means the format expects one separator, such as the dash in Y-m-d, where the string has another, such as the slash in 21/11/2026. A day-first input read with a year-first format produces this and similar day, month or year errors. In Laravel 13, Eloquent date casts fall back to Carbon::parse when the format does not fit, so the failing call is almost always an explicit createFromFormat in your code.

Check
grep -rn "createFromFormat(" app/

Fix

Write the format the way the input really arrives, and reject other shapes in validation before parsing.

Fix
$request->validate([
    'starts_on' => ['required', 'date_format:d/m/Y'],
]);

$startsOn = Carbon::createFromFormat('!d/m/Y', $request->input('starts_on'));

Verify

With the corrected format the call returns a Carbon date for 21 November 2026 at midnight instead of throwing.

Verify
php artisan tinker --execute="dump(Carbon\Carbon::createFromFormat('!d/m/Y', '21/11/2026'))"

Confirmed by github.com

Did this fix it?

Cause 2 of 3

The input carries more than the format describes

You seeTrailing data, with the position pointing just after the part the format covers

Check

Trailing data means the format matched the start of the string but text remained afterwards: a time after a date, fractional seconds, a T separator or a time zone suffix such as Z from a JavaScript ISO string.

Check
php artisan tinker --execute="DateTimeImmutable::createFromFormat('Y-m-d', '2026-11-21 10:30:00'); dump(DateTimeImmutable::getLastErrors());"

Fix

Add the remaining parts to the format. For a full ISO 8601 string, Carbon::parse reads it without a format. The + specifier turns trailing data into a warning, but only use it when the extra text really does not matter.

Fix
Carbon::createFromFormat('Y-m-d H:i:s', '2026-11-21 10:30:00');

// ISO 8601 from a browser, for example 2026-11-21T10:30:00.000Z
Carbon::parse($request->input('sent_at'));

Verify

The value parses and the hours and minutes on the Carbon instance match the input.

Verify
php artisan tinker --execute="dump(Carbon\Carbon::createFromFormat('Y-m-d H:i:s', '2026-11-21 10:30:00')->format('H:i'))"

Confirmed by php.net

Did this fix it?

Cause 3 of 3

The input is shorter than the format

You seeNot enough data available to satisfy format (worded Data missing before PHP 8.1)

Check

Not enough data available to satisfy format means the string ended while the format still had fields left, for example a date-only value read with Y-m-d H:i:s. PHP releases up to 8.0 reported the same case as Data missing.

Check
php artisan tinker --execute="DateTimeImmutable::createFromFormat('Y-m-d H:i:s', '2026-11-21'); dump(DateTimeImmutable::getLastErrors());"

Fix

Use a date-only format for date-only input. Prefix it with ! so the missing time fields become zero instead of the current time, which createFromFormat fills in otherwise.

Fix
$day = Carbon::createFromFormat('!Y-m-d', '2026-11-21'); // 2026-11-21 00:00:00

Verify

The result shows midnight, not the time the code ran.

Verify
php artisan tinker --execute="dump(Carbon\Carbon::createFromFormat('!Y-m-d', '2026-11-21')->toDateTimeString())"

Confirmed by php.net

Did this fix it?

How do I stop it coming back?

  • Validate every user-supplied date with date_format using the same format string the parser uses, kept in one constant.
  • Send dates from the front end as ISO 8601 and read them with Carbon::parse instead of hand-written formats.
  • Start date-only formats with ! so stray current-time values never end up in stored dates.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Spotless Laundry, EZ Estimater.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.