How to pass date value using JQuery UI + Laravel
My problem is I am getting a 0000-00-00 00:00:00 value. Entry field:
<input id="datepicker2" type="text" name="unload_date">
$(function () {
$("#datepicker1").datepicker({
format: "dd MM yyyy",}
);
$("#datepicker2").datepicker({
format: "dd MM yyyy",
});});
The problem is, I only want to pass the date to my database as a value. My migrations look like this.
public function up()
{
Schema::table('orders', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('load_target', 255);
$table->dateTime('load_date');
$table->string('unload_target', 255);
$table->dateTime('unload_date');}}
Timestamps work fine, but why can't I pass my values ββ(load_date, unload_date)
I am using EloQentORM savings
$order->unload_date=Input::get('unload_date');
$order->save();
How to solve this? What time format should I use, or should I use a particular tool, lib?
I want to pass the value my yyyy MM dd to a MySql database.
Please leave an idea where to look for problems?
I found this:
$order->unload_date=date("Y-m-d",strtotime(Input::get('unload_date));
This is a good decision? are there any shorter solutions? By the way, I changed:
format:"yyyy-mm-dd"
in JQuery
source to share
use Datetime
for date formatting.
for best practice, put the following code in your model order
.
public function setUnloadDateAttribute($date)
{
$datetime = new DateTime();
$datetime->createFromFormat('d m Y', $date);
$this->attributes['unload_date'] = $datetime->format('Y-m-d H:i:s');
}
source to share