+ Reply to Thread
Results 1 to 20 of 20

Return month based on day of the year

  1. #1
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Return month based on day of the year

    Hello everyone,

    I have a sheet with the following values:

    280315 085B 10:24 2R

    The '085' is the 85th day of the year.
    I would like a formula that reads that part of the data, and return the month that day is in, in the "jan", "feb", "mar", etc. format.

    Thanks in advance,

    Marco

  2. #2
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Return month based on day of the year

    Try

    =TEXT("1/1"+MID(A1,8,3)-1,"mmm")


    If you want to have the actual date (not just a text string of the month), remove the text function

    ="1/1"+MID(A1,8,3)-1
    Format the cell as a date.

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Return month based on day of the year

    Does your data ALWAYS follow that format?

    The day number is ALWAYS a 3 digit string starting at character number 8?

    What year is this for? 2014?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Return month based on day of the year

    Try this one

    =TEXT(REPLACE(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),255,255)),4,1,""),"mmm")

    A
    B
    1
    280315 085B 10:24 2R Mar
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  5. #5
    Valued Forum Contributor
    Join Date
    07-04-2012
    Location
    Cape Town, RSA
    MS-Off Ver
    Office 365 ProPlus
    Posts
    1,050

    Re: Return month based on day of the year

    Assuming your code is in cell A1, use this formula:

    =CHOOSE(MONTH(DATE(YEAR(TODAY()),1,1+MID(A1,8,3)*1)),"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")

  6. #6
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Return month based on day of the year

    Thanks Jonmo for the quick solution. It indeed works.
    Can you explain me what the "1/1" does in this formula?
    I know what the MID part does. Also, thanks for the other option to show the date. I wonder if it also works correctly in a leap year.
    Quote Originally Posted by Jonmo1 View Post
    Try
    =TEXT("1/1"+MID(A1,8,3)-1,"mmm")
    If you want to have the actual date (not just a text string of the month), remove the text function

    ="1/1"+MID(A1,8,3)-1
    Format the cell as a date.
    The format is always the same like this:
    280315 085B 10:24 2R
    120814 100A 22:21 1R

    The 3 digits, in this case 085 and 100, represent the day of the year.
    Currently this is indeed for 2014, but it should work every year. Every year the digits restart at 001. (January 1)

    Kind regards,

    Marco
    Quote Originally Posted by Tony Valko View Post
    Does your data ALWAYS follow that format?

    The day number is ALWAYS a 3 digit string starting at character number 8?

    What year is this for? 2014?

  7. #7
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Return month based on day of the year

    So many replies, I cannot keep up. Thanks for all replies!

  8. #8
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Return month based on day of the year

    The 1/1 represents January 1st

    When excel is given a Date and the Year is omitted (1/1), then the current year is assumed.

    So this formula will always assume the date is in the current year.

    Yes, it will work in a leap year (still assuming the date is intended to be in the current year)

  9. #9
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Return month based on day of the year

    I've tried all your suggestions and I noticed something.
    I've used the following data (in A1) as example:
    211215 090B 12:34 2R

    The day of the year in this string is '090', which is the last day of March.
    Jonmo's formula results: "mar", which is correct.
    AlKey's formula results "mar" as well.
    RudiS' formula already shows "apr", which is wrong in this case.

    When I change the day to '091' which is April 1st, Jonmo's formula changes to "apr", while the others stay the same.
    AlKey's formula changes to "apr" on day '092', which is April 2nd.

    Quote Originally Posted by AlKey View Post
    Try this one
    =TEXT(REPLACE(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),255,255)),4,1,""),"mmm")

    A
    B
    1
    280315 085B 10:24 2R Mar
    Quote Originally Posted by RudiS View Post
    Assuming your code is in cell A1, use this formula:
    =CHOOSE(MONTH(DATE(YEAR(TODAY()),1,1+MID(A1,8,3)*1)),"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")
    Quote Originally Posted by Jonmo1 View Post
    The 1/1 represents January 1st
    When excel is given a Date and the Year is omitted (1/1), then the current year is assumed.

    So this formula will always assume the date is in the current year.
    Yes, it will work in a leap year (still assuming the date is intended to be in the current year)
    Thanks for explaining. The data is indeed for the current year. It will always be like that when new entries are added. The new entries will always be for the year they were added.
    Thanks for the solution!

  10. #10
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Return month based on day of the year

    Quote Originally Posted by Marco-Kun View Post
    The new entries will always be for the year they were added.
    Thanks for the solution!
    Hmm, we may have a misunderstanding here..

    The formula will ALWAYS return the date for the current year (when the formula is calculated)
    So if you use this formula in December for data that was created in December, They will represent dates in 2014.
    Then you save the book, close it etc..
    Then come January and you need to look at that December book again, the dates will now show for 2015.

  11. #11
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Return month based on day of the year

    That's correct, didn't think of that.
    Perhaps it's an idea to copy/paste special values for all entries that have a 'jan', 'feb', 'mar' entry when closing the file? So that only the values remain instead of the formula so that the data will be correct, no matter what year you open it?

    I guess I can figure something like that out with the macro recorder ^^
    Quote Originally Posted by Jonmo1 View Post
    Hmm, we may have a misunderstanding here..

    The formula will ALWAYS return the date for the current year (when the formula is calculated)
    So if you use this formula in December for data that was created in December, They will represent dates in 2014.
    Then you save the book, close it etc..
    Then come January and you need to look at that December book again, the dates will now show for 2015.

  12. #12
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Return month based on day of the year

    Yes, either that or..

    Is there anything else in the data that indicates which year it is?
    It doesn't have to be in the same cell, maybe an adjescent column?

  13. #13
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Return month based on day of the year

    The formula I have provided calculate from day 0 and it should have been 1 and that is why it was off by one day. Here is the correct one

    =TEXT(REPLACE(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),255,255)),4,1,"")+1,"mmm")

    Thanks

  14. #14
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Return month based on day of the year

    Quote Originally Posted by Jonmo1 View Post
    Yes, either that or..
    Is there anything else in the data that indicates which year it is?
    It doesn't have to be in the same cell, maybe an adjescent column?
    Hmm yes, there is a column with the year. I cannot look at the workbook at the moment, and I cannot recall if it's next to the cell with the data.

    I do know that the current workbook has cells from the year 2013, and 2014.

    Quote Originally Posted by AlKey View Post
    The formula I have provided calculate from day 0 and it should have been 1 and that is why it was off by one day. Here is the correct one
    =TEXT(REPLACE(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),255,255)),4,1,"")+1,"mmm")
    Thanks
    Alright, thanks ^^ I didn't notice that. Thanks for the reply!

  15. #15
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Return month based on day of the year

    Great, so let's just say B1 has the Year # (just the number, not a date)

    =TEXT(("1/1/"&B1)+MID(A1,8,3)-1,"mmm")

  16. #16
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Return month based on day of the year

    Great, works perfectly. Thanks for the assistance. Much easier than the copy/paste solution.

    Quote Originally Posted by Jonmo1 View Post
    Great, so let's just say B1 has the Year # (just the number, not a date)
    =TEXT(("1/1/"&B1)+MID(A1,8,3)-1,"mmm")
    Last edited by Marco-Kun; 03-27-2014 at 11:19 AM.

  17. #17
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Return month based on day of the year

    Quote Originally Posted by Jonmo1 View Post
    Great, so let's just say B1 has the Year # (just the number, not a date)
    =TEXT(("1/1/"&B1)+MID(A1,8,3)-1,"mmm")
    Also, is it possible to return the actual date with this formula? Like in the first one you gave me?
    I tried removing the Text function but it didn't work.

  18. #18
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Return month based on day of the year

    For just the date, it's

    =("1/1/"&B1)+MID(A1,8,3)-1

    Format the cell as a Date.

  19. #19
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Return month based on day of the year

    Thanks! I see what I did wrong. I removed the '()' around the first part too, giving me a weird output.
    Quote Originally Posted by Jonmo1 View Post
    For just the date, it's

    =("1/1/"&B1)+MID(A1,8,3)-1

    Format the cell as a Date.

  20. #20
    Forum Guru Jonmo1's Avatar
    Join Date
    03-08-2013
    Location
    Bryan, TX
    MS-Off Ver
    Excel 2010
    Posts
    9,763

    Re: Return month based on day of the year

    Without those parens, it's calculated like this

    ="1/1/"&B1+MID(A1,8,3)-1

    B1+MID() is done first
    so if B1 is 2014 and MID(A1,8,3) is 085
    Then it becomes 2014 + 085 = 2099

    The parens make it do the ("1/1/"&B1) first

  21. #21
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Return month based on day of the year

    This one will give you the real date

    =--TEXT(REPLACE(TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",255)),255,255)),4,1,"")+1,"mm/dd")

    Format cells as Date

+ 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. Change year but keep the month the same based on current year
    By Jamon Fries in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-11-2014, 05:29 PM
  2. Return value of the last week of the month based on the year and month
    By stevekho2 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 09-14-2013, 11:04 AM
  3. Type in Month-Year and return 3rd wednesday of month
    By learntheweek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-09-2010, 11:29 AM
  4. Replies: 3
    Last Post: 06-14-2006, 05:07 PM
  5. Formula to return last day of month for each month in year?
    By StargateFan in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-03-2006, 12:10 AM

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