SQL query for Date field
-
Friends, I've a table in SQL server database. One field in this table is of type "smalldatetime". When i run any query i get the date in the form :
5/6/2004
But i want to get the result in "descriptive" form i.e "Saturday, May 6, 2004". How can i get it with a query ? Imtiaz -
Friends, I've a table in SQL server database. One field in this table is of type "smalldatetime". When i run any query i get the date in the form :
5/6/2004
But i want to get the result in "descriptive" form i.e "Saturday, May 6, 2004". How can i get it with a query ? ImtiazYou can query it like this (just replace GETDATE() with your column):
SELECT DATENAME("dw", GETDATE()) + ', ' + DATENAME("m", GETDATE()) + ' ' + CAST(DAY(GETDATE()) AS VARCHAR) + ', ' + CAST(YEAR(GETDATE()) AS VARCHAR)
I'd suggest you just query out the DATETIME field and process it in your platform of choice. The .NET framework has, amongst others, very good localisation support for this that you could use to get the proper string for the proper locale setting. The use of DATENAME is dependant on how SQL Server processes it and thus it cannot be formatted to the users' locale/preferences (at least not to my knowledge). Hope this helps. -- Henrik Stuart (http://www.unprompted.com/hstuart/[^])