Thursday, 11 May 2017

Laravel - Change Date Format


Change Date Time Format (Laravel 5.3 Above)

Below shows how the the default time picker were change into date time format that can be safe into database . This also could be use to display user date into view page.

public function update(Request $request, $id)
{
  $alumni = Alumni::find($id); //retrieve fields from model class
  date('Y-m-d', strtotime($request["dob"])); //change date format to save in database
  $alumni->update($request->except('_token')); //return all request inputs

  \Session::flash('alert-success', 'Profile Successfully Updated'); //session flash
  return redirect(route('profile.index')); //redirect
}



Reference 


http://stackoverflow.com/questions/15567854/warning-date-format-expects-parameter-1-to-be-datetime

No comments:

Post a Comment