sql server convert date to string MM/DD/YYYY

前端 未结 5 1577
误落风尘
误落风尘 2020-11-27 20:14

I am using SQL Server 2008.

I have the following:

    select convert(varchar(20),fmdate) from Sery

How do I convert the date to str

相关标签:
5条回答
  • 2020-11-27 20:27

    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

    0 讨论(0)
  • 2020-11-27 20:27

    See this article on SQL Server Helper - SQL Server 2008 Date Format

    0 讨论(0)
  • 2020-11-27 20:28
    select convert(varchar(10), fmdate, 101) from sery
    

    101 is a style argument.

    Rest of 'em can be found here.

    T-SQL Cast / Convert date to string

    0 讨论(0)
  • 2020-11-27 20:40

    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 string

    Example:

    SELECT FORMAT(GETDATE(), 'MM/dd/yyyy')
    

    Further Reading:

    • How to convert DateTime to VarChar
    • How to convert date to a format mm/dd/yyyy
    0 讨论(0)
  • 2020-11-27 20:41
    select convert(varchar(10), cast(fmdate as date), 101) from sery
    

    Without cast I was not getting fmdate converted, so fmdate was a string.

    0 讨论(0)
提交回复
热议问题