这是代码:
<?php
mysql_connect("localhost","root","1234");//连接数据库
mysql_select_db("system");//选择数据库
$res=mysql_query('select post_date from abc');//查询post_date字段数据
$row=mysql_fetch_array($res);//取出post_date字段数据
$time=date('Y-m-d H:i:s',$row['post_date']);//格式化成“年-月-日 时:分:秒”的格式
mysql_query('insert into abc (my_date) values ("'.$time.'")');//插入数据
//mysql_close();//关闭数据库,可以不加
?>

解决方案 »

  1.   


    已经有字段my_date存在,不是不应该用update更新?my_date默认是:0000-00-00 00:00:00,
    现在的情况是想post_date 转0000-00-00 00:00:00格式,并更新my_date
      

  2.   

    理解错了意思,呵呵,你要的代码是(我改了一些地方,应该是循环更新的):
    <?php
    $conn=mysql_connect("localhost","root","1234");//连接数据库
    mysql_select_db("system");//选择数据库
    $res=mysql_query('select post_date from abc');//查询post_date字段数据
    while($row=mysql_fetch_array($res))//取出post_date字段数据
    {
    $time=date('Y-m-d H:i:s',$row['post_date']);//格式化成“年-月-日 时:分:秒”的格式
    mysql_query('update abc set my_date="'.$time.'" where my_date="'.$row['post_date'].'"');//查找原来的行,然后替换(更新)数据
    }
    mysql_close($conn);//关闭数据库,可以不加
    ?>
      

  3.   

    <?php
    //定义数据库操作类
    class db{
           //类属性定义
           var $dbhost="localhost";//MYSQL主机
           var $dbuser="root";//连接帐户
           var $password="";//连接密码
           var $dbname="";//数据库名
          //变量引用
           function mysql($dbhost,$dbuser,$password,$dbname){
               $this->dbhost=$dbhost;
               $this->dbuser=$dbuser;
               $this->password=$password;
               $this->dbname=$dbname;
           }    //创建MYSQL连接
           function mycon(){
           @mysql_connect($this->dbhost,$this->dbuser,$this->password);
       }
       //选择相应的数据库
       function selectdb(){
       @mysql_select_db($this->db);
       }
       
           //创建数据库连接并选择相应数据库
           function createcon(){
               mysql_connect($this->dbhost,$this->dbuser,$this->password);
       mysql_query("SET NAMES 'GBK'");
               mysql_select_db($this->dbname);
           }
       //执行SQL语句,并返回结果集
           function fetch_array($sql){
               $result=mysql_query($sql);
               return mysql_fetch_array($result);
           }
       //执行SQL语句
       function query($sql){
           return mysql_query($sql);
       }
       //取得结果集数组
       function loop_query($result){
           return mysql_fetch_array($result);
       }
       //关闭数据库连接
       function close() {
           return mysql_close();
       }
       }
    ?>
      
      

  4.   

    <?php
    $conn=mysql_connect("localhost","root","1234");//连接数据库
    mysql_select_db("system");//选择数据库
    $res=mysql_query('select post_date from abc');//查询post_date字段数据
    while($row=mysql_fetch_array($res))//取出post_date字段数据
    {
        $time=date('Y-m-d H:i:s',$row['post_date']);//格式化成“年-月-日 时:分:秒”的格式
        mysql_query('update abc set my_date="'.$time.'" where my_date="'.$row['post_date'].'"');//查找原来的行,然后替换(更新)数据
    }
    mysql_close($conn);//关闭数据库,可以不加
    ?>还是不行
      

  5.   

    update abc set my_date=FROM_UNIXTIME(post_date,'%Y-%m-%d %h:%i:%s')
      

  6.   

    update abc set my_date = FROM_UNIXTIME(post_date);
      

  7.   

    update abc set `my_date` = FROM_UNIXTIME(`post_date`,'%Y-%m-%d %H:%i:%s');