I am using SQL Server 2008.
I have the following:
select convert(varchar(20),fmdate) from Sery
How do I convert the date to string such that it show as MM/DD/YYYY
bd1hkmkf1#
That task should be done by the next layer up in your software stack. SQL is a data repository, not a presentation system
You can do it with
CONVERT(VARCHAR(10), fmdate(), 101)
But you shouldn't
6tdlim6h2#
select convert(varchar(10), fmdate, 101) from sery
101 is a style argument.
Rest of 'em can be found here.
CAST and CONVERT (Transact-SQL) - Date and time styles
ipakzgxi3#
As of SQL Server 2012+, you can use FORMAT(value, format [, culture ])
FORMAT(
)
Where the format param takes any valid standard format string or custom formatting string
format
Example:
SELECT FORMAT(GETDATE(), 'MM/dd/yyyy')
Further Reading:
mm/dd/yyyy
rpppsulh4#
select convert(varchar(10), cast(fmdate as date), 101) from sery
Without cast I was not getting fmdate converted, so fmdate was a string.
4条答案
按热度按时间bd1hkmkf1#
That task should be done by the next layer up in your software stack. SQL is a data repository, not a presentation system
You can do it with
But you shouldn't
6tdlim6h2#
101 is a style argument.
Rest of 'em can be found here.
CAST and CONVERT (Transact-SQL) - Date and time styles
ipakzgxi3#
As of SQL Server 2012+, you can use
FORMAT(
value, format [, culture ])
Where the
format
param takes any valid standard format string or custom formatting stringExample:
Further Reading:
mm/dd/yyyy
rpppsulh4#
Without cast I was not getting fmdate converted, so fmdate was a string.