December 24, 2007

Determine the current week in a month

It is quiet easy to determine the current week in a year as shown below :


However, to determine the current week in a month, use this query written by AMB

select datediff(week, convert(varchar(6), getdate(), 112) + '01', getdate()) + 1

returns 5 as the date today is 24 December 2007

Did you like this post?
kick it on
subscribe via rss subscribe via e-mail
print this post follow me on twitter

About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal



6 Responses to "Determine the current week in a month"
  1. Pavan said...
    May 7, 2008 at 5:26 AM

    Dear Friend,

    Its more helpful.I am very thankful for providing this valuable information.bye.....

  2. Anonymous said...
    August 25, 2008 at 10:23 PM

    thanks a lot helped a lot

  3. Anonymous said...
    February 6, 2009 at 8:09 PM

    Me ayudaste mucho con este dato.

  4. Anonymous said...
    May 28, 2009 at 2:04 PM

    This was extremely helpful! You saved my day!!!!

  5. Anonymous said...
    June 22, 2009 at 7:17 AM

    Hi ,

    I tested out this SQL Statement and it doesn't seem to work. My week starts on a Monday, so I set SQLs DATEFIRST to 1.

    I then ran the statement and declared the date as '2009-06-07'. When I ran the query it returned the value 2, which is incorrect. It should've returned 1, as the 7th June 2009 is still part of the first week that starts on a Monday and ends on a Sunday.

    Any suggestions on how to get around this?

  6. Anonymous said...
    September 13, 2010 at 4:58 AM

    Try this instead
    datediff(week, convert(varchar(6),@Date, 112) + '01', dateadd(dd,-1,@Date)) + 1


Copyright © 2009-2016 All Rights Reserved for by Suprotim Agarwal | Terms and Conditions