+ Reply to Thread
Results 1 to 11 of 11

Date formatting weeknum coming out wrong

  1. #1
    Forum Contributor
    Join Date
    10-25-2012
    Location
    london,england
    MS-Off Ver
    365 but on mac
    Posts
    137

    Date formatting weeknum coming out wrong

    This has been part of a seperate thread but rules state that it should have its own questionsales summarised by week V2.xlsx

    There is a date colomn that comnes froma csv file

    most dates are in the format

    DDMMYY or DMMYY

    however I require the date week number of this date ( monday start day).

    it corrups certain weeks- I cant get the date to format correctly to pick up the right week.

    Any help/set ups I am doing wrong?

  2. #2
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Date formatting weeknum coming out wrong

    A bit long wounded ..

    =WEEKNUM(DATE(RIGHT(RIGHT(0&C2,6),2),MID(RIGHT(0&C2,6),3,2),LEFT(RIGHT(0&C2,6),2)))
    Life's a spreadsheet, Excel!
    Say thanks, Click *

  3. #3
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Date formatting weeknum coming out wrong

    A bit long wounded ..

    =WEEKNUM(DATE(RIGHT(RIGHT(0&C2,6),2),MID(RIGHT(0&C2,6),3,2),LEFT(RIGHT(0&C2,6),2)))

  4. #4
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Date formatting weeknum coming out wrong

    hi Tradesman. could you point us to which specific ones are wrong? but to pick Mon as the start day, you should use return type of "2" instead:
    =WEEKNUM(C2,2)

    1 starts from Sunday. seeing Ace_XL's formula, i'm not sure if i got you wrongly

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  5. #5
    Forum Contributor dogberry's Avatar
    Join Date
    07-15-2012
    Location
    Wales, UK
    MS-Off Ver
    Excel 2010
    Posts
    624

    Re: Date formatting weeknum coming out wrong

    Hi

    Are you getting the correct information from the CSV file when I converted the date numbers to actual dates they range from 18 Aug 1984 to 21st Feb 1989 is that correct?

    Chris
    Click my star if I helped Thanks

  6. #6
    Forum Contributor
    Join Date
    10-25-2012
    Location
    london,england
    MS-Off Ver
    365 but on mac
    Posts
    137

    Re: Date formatting weeknum coming out wrong

    I wish i knew how to do that - could you explain the thought process - how does right(0&c2,6) work??

  7. #7
    Forum Expert Ace_XL's Avatar
    Join Date
    06-04-2012
    Location
    UAE
    MS-Off Ver
    2016
    Posts
    6,074

    Re: Date formatting weeknum coming out wrong

    Quote Originally Posted by Tradesman View Post
    I wish i knew how to do that - could you explain the thought process - how does right(0&c2,6) work??
    Firstly, does the formula give you desired results? you might want to use

    Please Login or Register  to view this content.
    depending on the start day being Monday

    right(0&c2,6) picks only the 6 rightmost characters of 0&c2. Hence 30912 becomes 030912 and rightmost 6 characters gives you 030912, while 271112 becomes 0271112 and 6 rightmost gives you 271112; giving you consistent 6 caharcters to ascertain dates

  8. #8
    Forum Contributor
    Join Date
    10-25-2012
    Location
    london,england
    MS-Off Ver
    365 but on mac
    Posts
    137

    Re: Date formatting weeknum coming out wrong

    Ho dogberry, the dates from the csv file cpome out in the dmmyy or ddmmyy range! my excels doing what yours is

    =WEEKNUM(DATE(RIGHT(RIGHT(0&C2,6),2),MID(RIGHT(0&C2,6),3,2),LEFT(RIGHT(0&C2,6),2)))

    this works a treat!

  9. #9
    Forum Contributor
    Join Date
    10-25-2012
    Location
    london,england
    MS-Off Ver
    365 but on mac
    Posts
    137

    Re: Date formatting weeknum coming out wrong

    Thanks guy

    acr-XL - superb

  10. #10
    Forum Expert icestationzbra's Avatar
    Join Date
    01-07-2004
    MS-Off Ver
    2007, 2010
    Posts
    1,421

    Re: Date formatting weeknum coming out wrong

    if Sunday start day:

    Please Login or Register  to view this content.
    if Monday start day:

    Please Login or Register  to view this content.
    Last edited by icestationzbra; 11-29-2012 at 12:58 PM.
    - i.s.z -
    CSE, aka Array aka { }, formulae are confirmed with CONTROL+SHIFT+ENTER.
    Replace commas ( , ) with semicolons ( ; ) in formulae, if your locale setting demands.
    All good ideas are courtesy resources from this forum as well as others around the web.
    - e.o.m -

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

    Re: Date formatting weeknum coming out wrong

    Many date functions in Excel can handle a text formatted date just as easily as an actual date, WEEKNUM is one of those, so in fact you could even eliminate the "coercers" -- and use

    =WEEKNUM(TEXT(C2,"00-00-00"),2)

    ......but if you are trying to summarise by week then using WEEKNUM might not be the best way because at the start and end of the year weeks could have as few as 1 day (e.g. 2012 week 1 has only 1 day if you use Monday as the start date).

    You might be better served using ISO week numbers (where all dates have 7 days - week 1 may start at the end of the previous year) or by using week start dates rather than week numbers
    Audere est facere

+ 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