+ Reply to Thread
Results 1 to 10 of 10

Subtract 1 week from a special dateformat

  1. #1
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Subtract 1 week from a special dateformat

    I got a funny problem with a part of my macro.

    Basically I got a big datafile with a lot of columns with data. In columns "O" (15) there is a "date" in the following format; yyyyww, for example 201648 which is the year 2016 in the week 48. In column "AB" (28) there is another column where I in my code filling the rows with some data. If column "O" is the start week of an event then column "AB" is the start week of the preparation for the event which always will be 1 week earlier than the start week of event (Column O). Therefore my code was taking the "date" in column "O" minus 1 week which will be correct most of the times. 201648 - 1 = 201647. The problem is that if for example the start week in column "O" is 201701 then my date in column "AB" will be 201700 which obviously is wrong. Instead it should give me 201652 since year 2016 is a total of 52 weeks. Is there a way to work around this?

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Subtract 1 week from a special dateformat

    How about:

    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Subtract 1 week from a special dateformat

    Hello try this code
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  4. #4
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Subtract 1 week from a special dateformat

    Thx for both of your the answers. Your code is a upgrade from my code yet but the thing is that one week earlier of 201501 might be 201453 since a year can both have 52 and 53 weeks if I am correct. Do you see the problem?

  5. #5
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Subtract 1 week from a special dateformat

    Here, try this:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Subtract 1 week from a special dateformat

    That looks a lot better! But shouldn't the code be the following? Since it will have to take the last weeknumber of the previous year? Om maybe I am wrong.

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-07-2014
    Location
    Göteborg
    MS-Off Ver
    2010
    Posts
    130

    Re: Subtract 1 week from a special dateformat

    And another thing, tell me if I am wrong but according to my calendar 2016 only has 52 weeks. But If I run the formula I get 201653 from 201701.
    Its the same in excel if I have the following formula: =WEEKNUM(DATE(2016;12;31);2) and it gives me 53. I know that =WEEKNUM has different return types but 2 is start on Monday so I am not sure why it give me week 53.

  8. #8
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,596

    Re: Subtract 1 week from a special dateformat

    There are two systems used for this function:
    • System 1 The week containing January 1 is the first week of the year, and is numbered week 1.
    • System 2 The week containing the first Thursday of the year is the first week of the year, and is numbered as week 1. This system is the methodology specified in ISO 8601, which is commonly known as the European week numbering system.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 01-09-2016, 04:39 PM
  2. VBA DateFormat
    By jagadeesh.rt in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-29-2014, 02:48 AM
  3. [SOLVED] Subtract two dates to get # of week days - networkdays does not quite work
    By loree1223 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-10-2013, 10:17 PM
  4. [SOLVED] Display Week Number based on special requirements
    By PY_ in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 03-05-2013, 08:50 AM
  5. Replies: 7
    Last Post: 03-02-2012, 07:51 PM
  6. Copy and paste special by week number
    By robertc12 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2009, 06:50 AM
  7. Dateformat
    By Kjeldc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-13-2005, 05:06 PM

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