• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 77
  • Last Modified:

Find Monday in iso_week 1

Hi!

I need a sql query to provide me the Monday in iso_week 1 for any given year.

in 2015 it should return '2014-12-29'
in 2016 it should return '2016-01-04'
in 2017 it should return '2017-01-02'

Thanks,
0
intimenordic
Asked:
intimenordic
1 Solution
 
Phillip BurtonCommented:
Either:

select dateadd(day,2-datepart(dw,'20130101')+iif(datepart(dw,'20130101')>5,7,0),'20130101') as ISOWeek1

Open in new window


or, if you want to define it once:

declare @year as char(4)
set @year = '2027'

select dateadd(day,2-datepart(dw,@year + '0101')+iif(datepart(dw,@year + '0101')>5,7,0),@year + '0101') as ISOWeek1

Open in new window

0
 
intimenordicAuthor Commented:
Perfect! Just used getdate for declaring, since this is a runtime thing.

declare @year as char(4)
set @year = year(getdate())
select dateadd(day,2-datepart(dw,@year + '0101')+iif(datepart(dw,@year + '0101')>5,7,0),@year + '0101') as ISOWeek1

Thanks, and have a great weekend!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now