I want to SELECT a formatted date string from a datetime
type in SQL Server 2005.
In the format "yyyy/mm/dd hh:mm:ss".
What is the best way to do using only a query?
I want to SELECT a formatted date string from a datetime
type in SQL Server 2005.
In the format "yyyy/mm/dd hh:mm:ss".
What is the best way to do using only a query?
Check out the CONVERT statement.
SELECT CONVERT(VARCHAR(20), getdate(), 120)
is closest to what you want. (Note the different separators (- instead of / ))
select convert(varchar, datetime_field, 120) from tablename;
will do almost what you want.
120
is the conversion "style", see here for more.