0

I can't seem to get a timestamp in a format that my database seeder will accept.

I am running this command in php artisan tinker:

$faker->dateTimeThisYear($max = '+1 year')->format('Y-m-d H:i:s')

Which produces:

"2015-03-17 01:26:44"

As far as I can tell, this matches the format that the database expects (0000-00-00 00:00:00). However, when I try to seed the DB I get the following errors:

 [InvalidArgumentException]                
  The separation symbol could not be found  
  Unexpected data found.                    
  Hour can not be higher than 12            
  Unexpected data found.                    
  A meridian could not be found

Every other variation I've tried including passing an actual DateTime object has not worked either. Not even this format: 'YYYY-MM-DD HH:mm:ss'

This doesn't work either:

DateTime::createFromFormat('Y-m-d H:i:s', '2000-05-05 22:22:22')

Error:

DateTime::createFromFormat() expects parameter 2 to be string, object given

Most disturbingly is that in the migrations for that column, I can specify Carbon::now() as the default value and it works with no problem. It's only when seeding that these errors crop up. It won't even let me use Carbon::now() when seeding.

Migration:

$table->timestamp('time_available')->default(Carbon::now());

Seeding:

$factory->define(App\AvailableMeeting::class, function (Faker\Generator $faker) {
return [
    'office_id' => 1,
    'worker_id' => 1,
    'length_minutes' => $faker->numberBetween(14,61),
    'time_available' => $faker->dateTimeThisYear('+1 year')->format('Y-m-d H:i:s') // doesn't work.. neither does Carbon::now()
    ];
});

Database:

database

Your thoughts are appreciated!

Marcel Gruber
  • 6,668
  • 6
  • 34
  • 60
  • Can you post the actual seeder code that sets the date, please, if that's where the error is coming from? (Also, when you say it won't "let" you use Carbon::now when seeding, what's the error you get?) – Matt Gibson Oct 11 '15 at 21:07
  • Hey @MattGibson, I have updated the question. When I use `Carbon::now()` while seeding I get.... [InvalidArgumentException] The separation symbol could not be found Unexpected data found. Unexpected data found. Unexpected data found. A meridian could not be found – Marcel Gruber Oct 11 '15 at 21:14
  • (Also, can you post the database definition for the table you're trying to insert into? Bear in mind you might find this your problem is actually coming from a different field, if, for example, you've accidentally defined one of the other columns as a date type and are now trying to insert the wrong kind of value into it...) – Matt Gibson Oct 11 '15 at 21:15
  • @MattGibson All the info should be there now. Thank you ! – Marcel Gruber Oct 11 '15 at 21:17

0 Answers0