Converting to mm/dd/yyyy format

前端 未结 2 1384
终归单人心
终归单人心 2021-02-10 19:10

I have a table called SF_Data and there is a column called IN_Date, ID the data looks like:

ID      IN_Date
1       9/8/2010
2       26/04/2011
3       20/09/201         


        
2条回答
  •  无人及你
    2021-02-10 19:54

    The 3rd parameter to convert has no meaning when converting from varchar to varchar. So per @marc_s' comment, you'd have to convert the varchar to a datetime using the 103 format, and then from datetime to varchar specifying the 101 format:

    Select convert(varchar(12),convert(datetime,IN_Date,103),101) From dbo.SF_Data
    

    For example:

    select convert(varchar(12),convert(datetime,'31/12/2001',103),101)
    

    prints 12/31/2001.

    See MSDN.

提交回复
热议问题