如何将 mysql2008 中的时间字段中的时间转为整数导入mysql 中?现在,sql2008 中的时间格式是:2009-06-24 17:25:00.000而dede mysql 时间格式是整数的,就是这样的格式:1270603757高手来啊请回,sql2008 中,有函数转成整数不?

解决方案 »

  1.   


    select cast(cast('1900-1-2' as datetime) as int)
    select cast(getdate() as int)
      

  2.   


    dede实际时间为:2010-04-07
    转过去的时间为:1270603757
    而兄弟你的方法转的时间是:40274相差好多啊DEDE 的时间函数,我也贴 上来 function GetMkTime($dtime)
    {
    global $cfg_cli_time;
    if(!ereg("[^0-9]",$dtime))
    {
    return $dtime;
    }
    $dtime = trim($dtime);
    $dt = Array(1970,1,1,0,0,0);
    $dtime = ereg_replace("[\r\n\t]|日|秒"," ",$dtime);
    $dtime = str_replace("年","-",$dtime);
    $dtime = str_replace("月","-",$dtime);
    $dtime = str_replace("时",":",$dtime);
    $dtime = str_replace("分",":",$dtime);
    $dtime = trim(ereg_replace("[ ]{1,}"," ",$dtime));
    $ds = explode(" ",$dtime);
    $ymd = explode("-",$ds[0]);
    if(!isset($ymd[1]))
    {
    $ymd = explode(".",$ds[0]);
    }
    if(isset($ymd[0]))
    {
    $dt[0] = $ymd[0];
    }
    if(isset($ymd[1]))
    {
    $dt[1] = $ymd[1];
    }
    if(isset($ymd[2]))
    {
    $dt[2] = $ymd[2];
    }
    if(strlen($dt[0])==2)
    {
    $dt[0] = '20'.$dt[0];
    }
    if(isset($ds[1]))
    {
    $hms = explode(":",$ds[1]);
    if(isset($hms[0]))
    {
    $dt[3] = $hms[0];
    }
    if(isset($hms[1]))
    {
    $dt[4] = $hms[1];
    }
    if(isset($hms[2]))
    {
    $dt[5] = $hms[2];
    }
    }
      

  3.   

    dede实际时间为:2010-04-07
    转过去的时间为:1270603757
    而兄弟你的方法转的时间是:40274相差好多啊DEDE 的时间函数,我也贴 上来 
    PHP codefunction GetMkTime($dtime)
    {
        global $cfg_cli_time;
        if(!ereg("[^0-9]",$dtime))
        {
            return $dtime;
        }
        $dtime = trim($dtime);
        $dt = Array(1970,1,1,0,0,0);
        $dtime = ereg_replace("[\r\n\t]|日|秒"," ",$dtime);
        $dtime = str_replace("年","-",$dtime);
        $dtime = str_replace("月","-",$dtime);
        $dtime = str_replace("时",":",$dtime);
        $dtime = str_replace("分",":",$dtime);
        $dtime = trim(ereg_replace("[ ]{1,}"," ",$dtime));
        $ds = explode(" ",$dtime);
        $ymd = explode("-",$ds[0]);
        if(!isset($ymd[1]))
        {
            $ymd = explode(".",$ds[0]);
        }
        if(isset($ymd[0]))
        {
            $dt[0] = $ymd[0];
        }
        if(isset($ymd[1]))
        {
            $dt[1] = $ymd[1];
        }
        if(isset($ymd[2]))
        {
            $dt[2] = $ymd[2];
        }
        if(strlen($dt[0])==2)
        {
            $dt[0] = '20'.$dt[0];
        }
        if(isset($ds[1]))
        {
            $hms = explode(":",$ds[1]);
            if(isset($hms[0]))
            {
                $dt[3] = $hms[0];
            }
            if(isset($hms[1]))
            {
                $dt[4] = $hms[1];
            }
            if(isset($hms[2]))
            {
                $dt[5] = $hms[2];
            }
        }
      

  4.   

    select cast(datediff(ss,'1970-1-1 ','2010-04-07 1:29:17') as int)
      

  5.   

    就是这个。
    不过建议改为:select cast(datediff(ss,'1970-1-1 ','2010-04-07 1:29:17') as bigint)