문제

I am currently trying to turn a Datetime field into a Year + Week field. what i have is the following

    CreateDate
------------------------
2012-08-15 07:22:56.000
2012-11-16 10:10:00.000
2013-01-22 08:47:37.000
2013-01-22 08:55:18.000
2013-01-22 09:00:38.000
2013-01-29 16:26:25.000

and i want this

 Weekstamp
------------------------
2013-32
2013-33
2013-34
2013-35
2013-36
2013-37
2013-45

can anybody Show me how this is done ? Thanks a lot in advance.

도움이 되었습니까?

해결책

Use this code

        select (cast(Year(YourDateTimeColumn) as varchar(4))+'-'+cast(datepart(wk,YourDateTimeColumn) as varchar(2))) Weekstamp from YourTableName

다른 팁

Thanks for the Answers, here is a slightly better Approach that i've found.

convert(varchar, year(CreateDate)) + '-' +right('0' + convert(varchar, datepart(iso_week, CreateDAte)),2) as Weekstamp
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top