zoukankan      html  css  js  c++  java
  • PHP 输出MSSQL2005/2008数据DateTime字段类型问题

    Catchable fatal error: Object of class DateTime could not be converted to string inF:projectpublicweb.php on line 54

    决解方案一、

     $tmptsql="select * from mytable";
     $tmpstmt=sqlsrv_query($conn,$tmptsql);
     $tmprs=sqlsrv_fetch_array($tmpstmt);
     if( $tmpstmt === false )
     {
       echo "Error in statement preparation/execution. ";
       die( print_r( sqlsrv_errors(), true));
     }
     /* Make the first row of the result set available for reading. */
     if( sqlsrv_fetch( $tmpstmt ) === false )
     {
       echo "Error in retrieving row. ";
       die( print_r( sqlsrv_errors(), true));
     }
     echo sqlsrv_get_field( $tmpstmt, 2,SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));

    决解方案二、

    SELECT convert(char,你的日期字段,120) as date2 FROM table

    mssql默认以系统时间格式输出,你可以调整系统的时间格式来解决

    当然是在程序里解决比较灵活,convert(char,date,N)输出的各中样式 
    N 日期样式 
    0 04 2 2005 9:06AM 
    1 04/02/05 
    2 05.04.02 
    3 02/04/05 
    4 02.04.05 
    5 02-04-05 
    6 02 04 05 
    7 04 02, 05 
    8 09:06:18 
    9 04 2 2005 9:06:18:857AM 
    10 04-02-05 
    11 05/04/02 
    12 050402 
    13 02 04 2005 09:06:18:857 
    14 09:06:18:857 
    20 2005-04-02 09:06:18 
    21 2005-04-02 09:06:18.857 
    22 04/02/05 9:06:18 AM 
    23 2005-04-02 
    24 09:06:18 
    25 2005-04-02 09:06:18.857 
    100 04 2 2005 9:06AM 
    101 04/02/2005 
    102 2005.04.02 
    103 02/04/2005 
    104 02.04.2005 
    105 02-04-2005 
    106 02 04 2005 
    107 04 02, 2005 
    108 09:06:18 
    109 04 2 2005 9:06:18:857AM 
    110 04-02-2005 
    111 2005/04/02 
    112 20050402 
    113 02 04 2005 09:06:18:857 
    114 09:06:18:857 
    120 2005-04-02 09:06:18 
    121 2005-04-02 09:06:18.857 
    126 2005-04-02T09:06:18.857

  • 相关阅读:
    Spring 资源文件处理
    Mysql Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='
    JAVA NIO Socket通道
    JAVA NIO FileChannel 内存映射文件
    JAVA NIO Scatter/Gather(矢量IO)
    JAVA NIO Channel
    JAVA NIO Buffer
    MTU(Maximum transmission unit) 最大传输单元
    TCP建立连接之三次握手
    TCP首部解析
  • 原文地址:https://www.cnblogs.com/TT-1314/p/7122706.html
Copyright © 2011-2022 走看看