dongxie548548 2014-11-28 08:41
浏览 19

Php日期问题

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 Java-Oj-桌布的计算
    • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
    • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
    • ¥20 有人知道这种图怎么画吗?
    • ¥15 pyqt6如何引用qrc文件加载里面的的资源
    • ¥15 安卓JNI项目使用lua上的问题
    • ¥20 RL+GNN解决人员排班问题时梯度消失
    • ¥60 要数控稳压电源测试数据
    • ¥15 能帮我写下这个编程吗
    • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路