Posting this for others and for myself in case I forget the next time I need to use it.
I'm trying to take a date in Excel and turn it into a 3 character representation. I know how to do that using TSQL but others I work with that don't have access to TSQL tools and don't know how to script can also do some data formatting on their own.
I inserted the date...
3/18/2016
...in cell A1. In B1, I inserted what I thought the function would be but it didn't work...
=MONTH(A1)
This formula gave me a 3 in return instead of Mar. I was 99% sure that Excel had to have a function for this so after doing a Google search, I found what I was after and more.
There was a post that stated to use this formula...
=TEXT(MONTH(A1),"MMM")
...but that gave me Jan in return which is not good because the date I keyed in was March. I found an explanation of what that combination of functions did.
Using MONTH() only returns a number 1 through 12 depending on what date is in the cell. If you type in 1 in cell A1, 2 in A2 and all the way down to 12 in A12, convert that column to a date and you'll see that those are the first 12 dates in January of the year 1900.
If you have a number that includes or is between 1 through 12 in this formula...
=TEXT(6,"MMM")
...it's always going to return Jan as the month. The fastest way to get the 3 character representation of month is just to use the TEXT() function and not the MONTH() function.
=TEXT(A1,"MMM")
Typing that function into cell A2 when the date (3/18/2016 for example) is in A1 will give...
Mar
After doing my Google search, it came to me that if I right clicked on a column that has dates, click on Format Cells... click on Custom, and then in the Type: field type MMM, that would give you the same result.
No comments:
Post a Comment