In mysql databse I have wrong date value entered which column name is created_date
in contact_details
table and it's type is char(20)
which is wrong. There are 2500 more rows. Now I want to change all date value to correct format. Correct format will be y-m-d h:i and it's type will be datetime.
So For this I'm showing all rows from db to test.php page and It's showing following date value using this code.
$q=mysqli_query($link, "SELECT cdid, created_date, created_date2 FROM contact_details ORDER
BY cdid DESC");
while($r=mysqli_fetch_array($q)){
$c=$r['created_date'];
$cdid = $r['cdid'];
$c = str_replace("PM", " ", $c);
$c = str_replace("AM", " ", $c);
$c = str_replace("/", "-", $c);
$c = explode(" ", $c);
$date = $c[0];
$time = $c[1];
$date = explode("-", $date);
$value1 = $date[0];
$value2 = $date[1];
$value3 = $date[2];
$l =strlen($date);
echo "$date ($l)"; // for testing purpose I'm showing only date here..
There are more rows. I'm just showing you now 4 result..
2014-11-05 (y-m-d)
11-4-2014 (m-d-y)
11-4-2014 (m-d-y)
4-24-2007 (m-d-y)
So, How Do I updated this all date value to correct format using php and mysql ? Final Result will be y-m-d h:i format in mysql db.
I'm highly appreciated your help!