I created a webapp using Laravel and SQLite,everything was going great.Now,I want to use MySQL as database but now I am unable to add data to my tables.
This is the field from my migration:
$table->dateTime('last_updated')->nullable();
and this is how I am populating the field using laravel:
$client->last_updated = time();
But it is giving me error like:
Illuminate \ Database \ QueryException
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1402140378' for column 'last_updated' at row 1 (SQL: update `clients` set `last_updated` = 1402140378 where `id` = 1)
Any help will be appreciated.
$table->dateTime
creates an DATETIME
column in your database that expects a value of YYYY-MM-DD HH:ii:ss
. What you're inserting is a unix timestamp.
You can either use Carbon
(requires use Carbon\Carbon
at the top of your file),
$client->last_updated = Carbon::now()
date(...)
,
$client->last_updated = date('Y-m-d H:i:s')
or PHP's DateTime
class to insert the current datetime to the database..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With