Avatar of Steve_Brady
Steve_BradyFlag for United States of America

asked on 

Change the written name of a month into its numerical equivalent in Excel

Hello,

Is there a formula in Excel (2010) that will change the written name of a month into its numerical equivalent?

I frequently run across date entries in which the year and day are specified by numbers but the month is specified by a word. For example, the following is from the Date&Time column in a database of recorded events from a webpage:
...
May 20, 2012 7:55:14 PM          >>>          05/20/12
May 20, 2012 2:26:33 PM          >>>          05/20/12
May 20, 2012 9:33:20 AM          >>>          05/20/12
May 19, 2012 9:47:38 AM          >>>          05/19/12
May 18, 2012 11:57:02 PM          >>>          05/18/12
May 18, 2012 11:52:19 PM          >>>          05/18/12
May 18, 2012 12:42:01 PM          >>>          05/18/12
...

The long entries on the left reveal the format of the original data and the familiar 2-slash dates on the right display the desired format with the time discarded.

The following code effects the conversion:

=DATE(
    MID(A1,SEARCH(",",A1)+2,4),
    IF(LEFT(A1,3)="Jan",1,
        IF(LEFT(A1,3)="Feb",2,
        IF(LEFT(A1,3)="Mar",3,
        IF(LEFT(A1,3)="Apr",4,
        IF(LEFT(A1,3)="May",5,
        IF(LEFT(A1,3)="Jun",6,
        IF(LEFT(A1,3)="Jul",7,
        IF(LEFT(A1,3)="Aug",8,
        IF(LEFT(A1,3)="Sep",9,
        IF(LEFT(A1,3)="Oct",10,
        IF(LEFT(A1,3)="Nov",11,
        IF(LEFT(A1,3)="Dec",12)))))))))))),
    MID(A1,SEARCH(" ",A1)+1,SEARCH(",",A1)-1-SEARCH(" ",A1))
    )

Open in new window

However, it would certainly be a lot simpler and cleaner if there was a single function, etc., for the Month argument.  In fact, for something so common, I anticipate there is (a function) and I have just not yet learned it.  

In if that is not the case however, feel free to copy the following to save in your bag of shortcuts for the next time you need it.

=IF(LEFT(A1,3)="Jan",1,
IF(LEFT(A1,3)="Feb",2,
IF(LEFT(A1,3)="Mar",3,
IF(LEFT(A1,3)="Apr",4,
IF(LEFT(A1,3)="May",5,
IF(LEFT(A1,3)="Jun",6,
IF(LEFT(A1,3)="Jul",7,
IF(LEFT(A1,3)="Aug",8,
IF(LEFT(A1,3)="Sep",9,
IF(LEFT(A1,3)="Oct",10,
IF(LEFT(A1,3)="Nov",11,
IF(LEFT(A1,3)="Dec",12))))))))))))

Open in new window

Thanks
Microsoft Excel

Avatar of undefined
Last Comment
Steve_Brady
ASKER CERTIFIED SOLUTION
Avatar of dlmille
dlmille
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of nito8300
nito8300
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of nito8300
nito8300
Flag of United States of America image

Then you can just format the cells, select Custom and use mm/dd/yy
SOLUTION
Avatar of barry houdini
barry houdini
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
Avatar of byundt
byundt
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of dlmille
dlmille
Flag of United States of America image

barry, will =Month(1&A1) work with 3 character month names, as well?

Dave
Avatar of byundt
byundt
Flag of United States of America image

Dave,
Did it not do so in your tests?

It did in mine.

Brad
Avatar of dlmille
dlmille
Flag of United States of America image

Thanks for that, Brad, lol.

Neat stuff.  Amazing the backflips you guys come up with.  (by backflips, I mean the stuff that's not obvious).

Cheers,

Dave
Avatar of Steve_Brady
Steve_Brady
Flag of United States of America image

ASKER

Great responses.  Thanks
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo