How to get standard date values ​​in SQL Server

zhaozj2021-02-16  91

For example, the name of the date field is DATE_FIELD

I can use it as follows

$ link = MSSQL_Connect ("LocalHost", "SA", "SA");

$ Result = MSSQL_QUERY ("SELECT * from test_table", $ link);

While ($ RES = MSSQL_FETCH_ASSOC ($ Result) {

Print_R ($ RES);

}

The result is as follows

============================================================================================================================================================================================================= ====

ARRAY

User_name => "Hello";

DATE_FIELD => "2004 July 28 14:13"

)

The results and standard formats do not work on such problems?

You can solve this problem by changing the query statement.

Convert (char, your field name, 120) AS your field name

To solve this problem

The actual statement is like this

$ link = MSSQL_Connect ("LocalHost", "SA", "SA");

$ result = mssql_query ("Select User_Name, Convert (char, date_field, 120) as data_field from test_table, $ link);

While ($ RES = MSSQL_FETCH_ASSOC ($ Result) {

Print_R ($ RES);

}

The result is as follows

============================================================================================================================================================================================================= ====

ARRAY

User_name => "Hello";

Date_field => "2004-07-28 14:13:36"

)

Ok, you can get the date format correctly.

转载请注明原文地址:https://www.9cbs.com/read-11648.html

New Post(0)