Convert day of year to datetime in SQL Server

后端 未结 2 425
温柔的废话
温柔的废话 2021-01-20 04:54

In a database table (SQL Server 2012), I have dates saved in the yyyyxxx format, where xxx is the day of the year. For example 2015-08-11

2条回答
  •  执笔经年
    2021-01-20 05:20

    Since there is a good answer for the first question, let's talk about the second one.

    How about converting DATETIME to this format?

    DATENAME function can help to solve it. It's gonna look like that:

    SELECT DATENAME(year, @var) + RIGHT('00' + DATENAME(dayofyear, @var), 3)
    

提交回复
热议问题