We know that mssql cannot use time like PHP does. It generates the time format DateTime, so the display is incorrect, as follows
The code is as follows
代码如下 |
复制代码 |
while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC))
{
print_r($row['datetime']);//这个字段是mssql的时间格式
}
结果是
DateTime Object
(
[date] => 2011-10-20 00:00:00
[timezone_type] => 3
[timezone] => Asia/Chongqing
)
|
|
Copy code
|
while( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC))
{
Print_r($row['datetime']);//This field is the time format of mssql
}
The result is
DateTime Object
(
[date] => 2011-10-20 00:00:00
[timezone_type] => 3
[timezone] => Asia/Chongqing
)
|
Solution
The first method: define ini_set("mssql.datetimeconvert",0);
at the beginning of the php document
The second method: modify php.ini, find;mssql.datetimeconvert = On, remove the preceding semicolon, and change on to off.
The third method: only use the convert function to convert the time field of mssql into a string.
For example, SELECT *,convert(char,datetime field,120) as str_datetime FROM table name
This str_datetime is a string. The third parameter is 120, which is exactly the format we need yyyy-mm-dd hh:ii:ss
http://www.bkjia.com/PHPjc/630733.htmltruehttp: //www.bkjia.com/PHPjc/630733.htmlTechArticleWe know that mssql cannot use time like PHP does. It generates the time format DateTime, so the display is incorrect. , the following code is copied as follows while( $row = sqlsrv_fetch_array...