Support the ongoing development of →
Database Eloquent
Last updated 2 years ago.

You should be able to define a due date in the getDates() function and have it accessible as a Carbon instance:

Have you tried dumping the current value of $this->due_date and see what it's looks like? I suspect it might not be formatted in a way Carbon expects.

Last updated 2 years ago.

EDIT: Ok, not broken. I had assumed the date string coming from Sqlite was a standard formatted date, but it seems sqlite treats datetime fields as an unvalidated string, so didn't complain when I inserted the data (which is 'datey' enough I thought it had passed some kind of validation)

This still seems to be broken for me?:

Lets add a datetime:


Now we can output in a view


string(19) "2010:03:21 13:15:14"

So far so good, but that date is ugly. So we add to the model, this should mean we get a carbon instance instead of a string:

	public function getDates() { return array('created_at', 'updated_at', 'deleted_at', 'taken'); }

And BOOM "ErrorException Unexpected data found. Unexpected data found."

This is carbon.php, line 358. The function is

createFromFormat($format, $time, $tz = null);

but the error message 'Unexpected data found' is from PHPs dateTime's createFromFormat .

Looking at at the arguments we have:

Y-m-d H:i:s -> 2010:03:21 13:15:14

So I suspect the problem is the format has dashes and the date string colons. The format comes from illuminate/database/grammar.php, the date string from sqlite. Solution is to add to the sqlite grammer class:

public function getDateFormat()
		return 'Y:m:d H:i:s';

This fixes it for me, but I am not sure if this is simply a quirk of my environment (standard apache2/php5/sqlite from ubuntu 14.04) or a larger bug.

Last updated 2 years ago.

You could put this in your model:

protected $dates = ['due_date'];
Last updated 2 years ago.

Carbon::createFromFormat('Y-m-d H:i:s', $var)->diffForHumans();

the documentation on Carbon is quite extensive and clear on how to use it.


Sign in to participate in this thread!


Your banner here too?

tbergeron tbergeron Joined 6 Feb 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.