hi,
i think, the date format required by you "yyyy-mm-dd" is not generated from SQL. Though "yyyy/mm/dd" can be generated.
You can use CONVERT(CHAR(10),getDate(),111). this will return you "2001/06/19" for today.
You can see more date formats in SQL BOL for "CONVERT" function help.
There is no style you can choose to get yyyy-mm-dd format for dates using the CONVERT function. However, using the REPALCE function in conjunction with the CONVERT function, you can achieve what you want.
Select replace(convert(char(10), getdate(),111),'/','-') Terry
Thanks, but I am using PHP and the date field, an_datum, is now empty using this select;
$result=mssql_query("SELECT TOP 20 CONVERT(char(20),an_datum,111),an_isin,an_signaltyp,an_kommentar,an_kalla FROM tbl_analys ORDER BY an_datum DESC", $db);
You need to assign a name (ALIAS) to the converted column. In SQL Server, you can use the same name as the column.
$result=mssql_query("SELECT TOP 20 REPLACE(CONVERT(char(20),an_datum,111), '/','-') As an_datum , an_isin, an_signaltyp, an_kommentar, an_kalla FROM tbl_analys ORDER BY an_datum DESC", $db);
Terry
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.