-1
I’m not finding a solution to store only date, always required time.
Error:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value
-1
I’m not finding a solution to store only date, always required time.
Error:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect date value
1
The table field you want to save to is in format DateTime
, naturally it needs the time. To store only dates, use $this->date('campo')
in creating the table.
Already found as date $table->date('maturity')->nullable();
@Andrécabral posts a code snippet of the table creation and how you are saving so I can help you better.
My Store $data = date("Y-m-d H:i:s", strtotime($request->expiration_title)); $data = $request->all();
In the conversion, beyond the date, you are putting H:i:s
, which is the format of hour, minute and second. If you want to convert and save the date, I recommend using the Carbon
, with the following code: \Carbon\Carbon::createFromFormat('d-m-Y', $request->vencimento_titulo)
, assuming vencimento_titulo
be in day, month, year format. Another detail, in your model
, add the vencimento_titulo
in the array
$dates
and get him out of the $fillable
, click here and see the documentation for more details.
It did not work, so the idea is that the user type: 31/12/2019 and the Standard make the conversion 2019-12-31
Then change the format of d-m-Y
for d/m/Y
and tell me what you produce. Then you can use the Carbon
to perform the conversion, then you can convert to string
and produce the date in the format desired to save or simply save the instance of Carbon
that Laravel will already recognize that it is a date.
[resolvi] The problem was in logic, thanks for the patience $date = str_replace("/", "-", $request->expiration_title); $date = Carbon Carbon::parse($date)->format('Y-m-d');
Browser other questions tagged laravel laravel-eloquent
You are not signed in. Login or sign up in order to post.
your bank is not as datetime and so the error happens?
– Gabriella Selbach
The format you are sending that is invalid, how are you sending the date? and could put the code?
– novic
The idea is that the user type so 31-01-2019 And in the bank stay so 2019-01-31
– André Cabral
You need to do this via code! if you can post the code?
– novic
My Store $data = date("Y-m-d", strtotime($request->expiration_title)); $data = $request->all();
– André Cabral