We know that mssql does not use time as php does. The generated time format DateTime is incorrect, as shown below:
The Code is as follows: |
Copy code |
While ($ row = sqlsrv_fetch_array ($ result, SQLSRV_FETCH_ASSOC )) { Print_r ($ row ['datetime']); // This field is in the time format of mssql. } The result is DateTime Object ( [Date] => 00:00:00 [Timezone_type] => 3 [Timezone] => Asia/Chongqing ) |
Solution
Method 1: Define ini_set ("mssql. datetimeconvert", 0) at the beginning of the php document );
Method 2: Modify php. ini and find; mssql. datetimeconvert = On. Remove the semicolon and change on to off.
Method 3: 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 the string. The third parameter is 120, which is in the format yyyy-mm-dd hh: ii: ss.