Ad

Saving Incorrect Date In MySQL Database

I am writing below code to convert the data to Date.

$date = strtotime($request->input('DueDate'));
$Job->DueDate = date('Y-m-d', $date);
$Job->save();

But this saves the data as 0000-00-00

Ad

Answer

Try this maybe: (createFromFormat's first argument should be the format which is being received by the user)

$dt = \DateTime::createFromFormat('m/d/Y', strtotime($request->input('DueDate')));
$Job->DueDate = $dt->format('Y-m-d');
$Job->save();

Cheers,,

Ad
source: stackoverflow.com
Ad