+ Reply to Thread
Results 1 to 17 of 17

Returning Week # per Month based on Date

  1. #1
    Forum Contributor 00Able's Avatar
    Join Date
    11-17-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    244

    Returning Week # per Month based on Date

    Based on the Date/Month/Year, I want to return the week number the date is.


    If cell a1 = 1/1/2012 then in b1 I want to return 1 (as it is in the 1st week of the month)
    If cell a1 = 2/6/2012 then in b1 I want to return 2 (as it is in the 2nd week of the month)
    If cell a1 = 1/31/2012 then in b1 I want to return 5 (as it is the 5th week of the month)
    If cell a1 = 2/1/2012 then in b1 I want to return 1 (as it is in the 1st week of the month)

    I have tried different versions of WeekNum formula but that isn't working, any ideas?

    Any ideas?
    Last edited by 00Able; 02-02-2012 at 06:53 PM.
    Providing Problems for Your Solutions
    STARS are my Punching Bag, You will be rewarded.

    In the rare event that I may help you, feel free to make me see STARS

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Returning Week # per Month based on Date

    00Able,

    Give this a try:
    =WEEKNUM(A2)-WEEKNUM(MONTH(A2)&"/1/"&YEAR(A2))+1
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Returning Week # per Month based on Date

    You can take some help from this thread - http://www.excelforum.com/excel-work...-in-month.html
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Contributor 00Able's Avatar
    Join Date
    11-17-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    244

    Re: Returning Week # per Month based on Date

    The formula :=WEEKNUM(A2)-WEEKNUM(MONTH(A2)&"/1/"&YEAR(A2))+1

    returns a 2 for the date 1/2/2012, which should be a one, then boosts every thing up a week, so 1/30 returns a 6? So it appears there is an issue with that formual, will continue to investigate...

  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Returning Week # per Month based on Date

    00Able,

    I am unable to duplicate the issues you described, see attached
    Attached Files Attached Files

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Returning Week # per Month based on Date

    Hello 00Able,

    How are you defining the week numbers? Are the first 7 days of the month in week 1, the next 7 in week 2 etc.......or do you want each week to start on a specific day (like Monday or Sunday for example). If it's the latter then do you want some weeks that straddle months, so that week 5 could go into the next month or week 1 could start in the previous month.

    If it's the first option (which fits all your examples) then try just

    =INT((DAY(A1)+6)/7)

    If that doesn't work for you then please explain the rules,
    Audere est facere

  7. #7
    Forum Contributor 00Able's Avatar
    Join Date
    11-17-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    244

    Re: Returning Week # per Month based on Date

    Alas I found my issue, I was using 2011 instead of 2012...=INT((13-WEEKDAY(A2)+DAY(A2))/7)
    and
    =WEEKNUM(A2)-WEEKNUM(MONTH(A2)&"/1/"&YEAR(A2))+1

    both work great!!!
    Thanks Guys!

  8. #8
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Returning Week # per Month based on Date

    I prefer the one without WEEKNUM but if you want to go with that version then Darkyam suggests a simplified non region-specific alternative (in the link posted by Arlette) to give the same result, i.e.

    =WEEKNUM(A2)-WEEKNUM(A2-DAY(A2)+1)+1
    Last edited by daddylonglegs; 02-02-2012 at 07:32 PM.

  9. #9
    Forum Contributor 00Able's Avatar
    Join Date
    11-17-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    244

    Re: Returning Week # per Month based on Date

    Well I thought that was going to work but apparently it is not. It does work for what I originally stated, but since found out that the Week ending dates are always going to be Sunday.
    So any day before and including the first Sunday would be in Week 1, anything before and including the 2nd Sunday would be in Week 2, etc...

    So for:
    1/8 would need to return 1
    1/15 would need to return 2
    1/22 would need to return 3
    1/29 would need to return 4
    1/31 would need to return 5
    2/1 would need to return 1

    Wish I woulda realized this in the first place...

  10. #10
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Returning Week # per Month based on Date

    Try this

    =INT((13-WEEKDAY(A2,2)+DAY(A2))/7)

    or this

    =WEEKNUM(A2,2)-WEEKNUM(A2-DAY(A2)+1,2)+1

  11. #11
    Forum Contributor 00Able's Avatar
    Join Date
    11-17-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    244

    Re: Returning Week # per Month based on Date

    No luck both of those are returning 6 for 1/31 and 2 for 1/8

  12. #12
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: Returning Week # per Month based on Date

    hello

    maybe
    =WEEKNUM(A2,21)

    ooppps
    2010 version.
    ill try in 2003 ( sorry )
    Last edited by vlady; 02-02-2012 at 08:52 PM. Reason: did try in 2003..wait
    I think people forget the word "THANK YOU!!!!" Do you still know it???

    There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "

    Regards,
    Vladimir

  13. #13
    Forum Contributor 00Able's Avatar
    Join Date
    11-17-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    244

    Re: Returning Week # per Month based on Date

    So, I looked at the equation again DaddyLongLegs and it appears it is doing exactly what it should...it appears because 1/1/2012 was a sunday, there is no week 1, as the first week entered was on 1/8, so the first week actually started on a non-work day...but it makes it look like we didn't work during week 1...hmmm not sure if there is a work around this exception, it only happens a few times a year...

  14. #14
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    Re: Returning Week # per Month based on Date

    @00Able from daddys formula.. I used 21...instead of 2 as stated in my previous post

    =WEEKNUM(A1,21)-WEEKNUM(A1-DAY(A1)+1)+1

    this is what i came ....

    1/20/2012 3
    1/31/2012 5
    2/1/2012 1
    1/15/2012 2
    1/8/2012 1
    1/22/2012 3
    3/1/2012 1
    5/1/2012 1
    2/28/2012 5
    5/1/2012 1
    4/2/2012 1


    when you used the 2 as return,, look at the date for 1/31/ 2012 ( 6 ) and 1/22/2010 ( 4 )

    don't know if this is correct..and whats the difference between 21 and 2 as return add but they are both monday..Or i just have an error on my dates entry??????

  15. #15
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Returning Week # per Month based on Date

    My last suggestions were based on your previous stipulation

    Quote Originally Posted by 00Able View Post
    So any day before and including the first Sunday would be in Week 1, anything before and including the 2nd Sunday would be in Week 2, etc...
    If 8th January is in week 1 then what week is 1st January in? If you can suggest a consistent rule then a formula can written to match it.

  16. #16
    Forum Contributor 00Able's Avatar
    Join Date
    11-17-2010
    Location
    Pittsburgh, PA
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    244

    Re: Returning Week # per Month based on Date

    This is the only consistent thing I can think of...

    =INT((13-WEEKDAY(A2,2)+DAY(A2))/7) this is correct unless A2 is both the 1st or 2nd day of the month and is either a Saturday or Sunday, then it needs to subtract 1

    So because 1/1/2012 is a Sunday, technically we didnt have a week 1, because the work week runs Monday-Sunday and we rarely ever work Saturday or Sunday. So in that case I would need 1/8/2012 to return week 1, and Jan 1, 2012 would be week 0, as it wouldn't be necessary...seems complicated

  17. #17
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Returning Week # per Month based on Date

    OK try the same formula but with 11 in place of 13, i.e.

    =INT((11-WEEKDAY(A2,2)+DAY(A2))/7)

    I think that'll give you the results you want.....

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1