Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

noblemfd's avatar

production.ERROR: The separation symbol could not be found

In my Laravel-5.8, I am trying to fomat date:

Model

public function setHireDateAttribute($value)
{
    $this->attributes['hire_date'] = Carbon::createFromFormat('d-m-Y', $value);
}
    
public function getHireDateAttribute($input)
{
    return Carbon::createFromFormat('Y-m-d', $input)
      ->format(config('app.date_format'));
}    

View:

<p for="">:{{ Carbon\Carbon::createFromFormat('d/m/Y', $employee->hire_date)->format('d-m-Y') }}</p>

When I rendered the view I got this error:

[2020-07-30 16:42:48] production.ERROR: The separation symbol could not be found Trailing data (View: C:\xampp\htdocs\laravelapp\resources\views\hr\employees\show.blade.php) {"userId":469,"exception":"[object] (ErrorException(code: 0): The separation symbol could not be found

How do I resolve this?

Thanks

0 likes
5 replies
Talinon's avatar

@noblemfd

The Trailing data portion of the error will be because of your use of createFromFormat().

You could correct it by instead doing this:

return Carbon::createFromFormat('Y-m-d H:i:s', $input)
      ->format(config('app.date_format'));

But, I think you're over engineering all this. From the looks of it, you just want a basic accessor for your view, right?

public function getHireDateAttribute($value)
{
    return Carbon::parse($value)->format(config('app.date_format'));
}    

Then within your view:

	{{ $employee->hire_date }}
noblemfd's avatar

@talinon - This works when I used

{{ $employee->hire_date }}

But it displays today's date when no date is available in the database

How do I resolve it?

Talinon's avatar

@noblemfd do you have a hire_date field in your database table?

If not, your accessor will use null for $value, which Carbon will parse into the current date.

noblemfd's avatar

@talinon - Yes, I have a field called hire_date. But no selected date in it.

Model

protected $fillable = [
              'id',
              'employee_code',
              'hire_date',
            ];


 protected $dates = [
     'hire_date',
  ];	

public function setHireDateAttribute($value)
{
    $this->attributes['hire_date'] = Carbon::createFromFormat('d-m-Y', $value);
}
    
public function getHireDateAttribute($input)
{
         return Carbon::parse($input)->format('d-m-Y');
}   

View

<p for="">: {{ $employee->hire_date }} </p>

But why is it showing today's date (Hire Date 30-07-2020) instead of null

Talinon's avatar
Talinon
Best Answer
Level 51

@noblemfd is the hire_date set to null?

Carbon will parse null to default system date.

You could do a check for that in your accessor method:

public function getHireDateAttribute($value)
{
    return is_null($value) ? "Unknown" : Carbon::parse($value)->format(config('app.date_format'));
}    

Please or to participate in this conversation.