Converting Text to Date

Mudbutt

Board Regular
Joined
Jul 18, 2011
Messages
158
I have two columns, in the first is the month (i.e. August), in the second is the year (i.e. 2011). However, i downloaded them from a database which formatted them as text and I need to use them in a formula in which it does not recognize these. How can i convert the month to the number of the month and convert the year to a yyyy date as it currently looks?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
This formula should work for you....

=--(A2&B2)

You will have format Column C with a Date cell format of your choice.
 
Upvote 0
This formula should work for you....

=--(A2&B2)

You will have format Column C with a Date cell format of your choice.

Now dats elegant.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
 
Upvote 0
Holy cow that -- is awesome. I need to look this up. The text conversion worked great, thanks guys!
 
Upvote 0
Holy cow that -- is awesome. I need to look this up.
The parentheses are important too. Also, 1* or 0- could have been used in place of the -- symbols. So, these formulas would have worked as well...

=1*(A2&B2)

=0+(A2&B2)

Excel tries to help its users as much as possible (sometimes it helps too much, but not in this case:)). Excel will take text concatenations that create numeric looking values and, when grouped in parentheses, convert them to real numbers if used in a mathematical operation. So, this would produce the real excel number 23...

=--("1"&"8")

The -- is a short cut for multiplying by minus one, twice. Since minus one times minus one is a plus 1, the mathematical operatiion converts the date to a number and multiplies it by plus one (as does the first alternative or adds 0 to it as does the second alternative). Now I know what you are saying to yourself... "Wait a minute, I have a date concatenated together, not a number!". Well, yes, that is technically true; however, dates to Excel are just floating point numbers... the integer portion is the number of days offset from an imaginary "date zero" (December 31, 1899 to Excel) and the decimal portion, if any, is the fraction of a 24-hour day represented by the decimal hours since midnight represented by the time part. Here is where Excel goes out of its way to help the user... it sees the text concatentation as being the shape of a date (I think this is where the parentheses comes into play) and ends up converting that text representation of the date into its underlying numeric value in response to the mathematical operation that the -- symbols impose on it. At least that is my interpretation of what is going on.
 
Upvote 0

Forum statistics

Threads
1,224,519
Messages
6,179,263
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top