String datetime insert into mysql database with codeigniter String datetime insert into mysql database with codeigniter codeigniter codeigniter

String datetime insert into mysql database with codeigniter


Use the correct MYSQL format for the date YYYY-MM-DD. For example change this in your code:

$data = array(    'Title' => $title,    'Description' => $description,    'When' => date('Y-m-d', strtotime($when)),    'Duration' => $duration,    'Where' => $where);


Dates in mySQL are YYYY-MM-DD

You are inserting a date MM/DD/YYYY

So try this:

$data = array(    'Title' => $title,    'Description' => $description,    'When' => date('Y-m-d', strtotime($when)),    'Duration' => $duration,    'Where' => $where);


Simplest way to store string date in any format in mysql

$srcFormat = "m/d/Y"; //convert string to php date$destFormat = "Y-m-d" //convert php date to mysql date string$data = array(  'Title' => $title,  'Description' => $description,  'When' => DateTime::createFromFormat($srcFormat, $when)->format($destFormat),  'Duration' => $duration,  'Where' => $where);