Solved

Find Monday in iso_week 1

Posted on 2015-02-20
2
70 Views
Last Modified: 2015-02-20
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
Comment
Question by:intimenordic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 24

Accepted Solution

by:
Phillip Burton earned 500 total points
ID: 40620857
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
 

Author Closing Comment

by:intimenordic
ID: 40620863
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question