I am generating fake dates between a specific interval with faker. Generated dates result TIMESTAMP
formate. I need to format it like 'Y-m-d' for insert into MySQL database table.
$events = $faker->dateTimeBetween('-30 days', '+30 days');
$dateFormate = Carbon::createFromTimestamp('Y-m-d H:i:s', $events )->format('Y-m-d');
But in the time of database seeding it gives an error
[ErrorException]
A non well formed numeric value encountered
Carbon::createFromTimestamp()
takes a timestamp (unix timestamp) as first argument and not a DateTime-object, which$faker->dateTimeBetween()
returns. Check out Carbons documentation – Knavedd($events)
– Oppressive