56

I have two cells in Excel. one has a string and the other one has a date. in the third cell I want to put the date and the string together. For example:

A1 = "This "
A2 = "03/03/1982"

I want A3 to be:

This 03/03/1982

when I try to put this in the A3 formula: = A1 & A2 it returns some funny numerical value for the date and does not give me the literal date.

3

6 Answers 6

84

Don't know if it's the best way but I'd do this:

=A1 & TEXT(A2,"mm/dd/yyyy")

That should format your date into your desired string.

Edit: That funny number you saw is the number of days between December 31st 1899 and your date. That's how Excel stores dates.

1
18

This is the numerical representation of the date. The thing you get when referring to dates from formulas like that.

You'll have to do:

= A1 & TEXT(A2, "mm/dd/yyyy")

The biggest problem here is that the format specifier is locale-dependent. It will not work/produce not what expected if the file is opened with a differently localized Excel.

Now, you could have a user-defined function:

public function AsDisplayed(byval c as range) as string
  AsDisplayed = c.Text
end function

and then

= A1 & AsDisplayed(A2)

But then there's a bug (feature?) in Excel because of which the .Text property is suddenly not available during certain stages of the computation cycle, and your formulas display #VALUE instead of what they should.

That is, it's bad either way.

5
  • This is so dumb (by Microsoft). The more annoying part of this is that even if you set your field type SPECIFICALLY to "Text" it will still spit out this magic number instead of what you actually want in the cell.
    – Erechtheus
    Feb 21, 2020 at 12:48
  • @starbyone It would be much dumber by Microsoft if it instead forced a certain textual representation of the date value when used in the context of concatenation. Same date can be represented in virtually unlimited number of ways, and the & operator should not get to pick the "right" way to display. The text type does work, but you need to actually change the value to text, not just change the cell format. That is, first apply the Text format, then paste the date-as-text value. Then the & will keep it as is (it always does that in fact, it's just that this time it will be more visual).
    – GSerg
    Feb 21, 2020 at 14:15
  • (1/2) I don't get why I have to paste it as text if the format on the cell is literally "text". If there was a numerical or date value there previously it should do an implicit casting/conversion. One would expect the value to be represented as text as soon as you change the formatting, it's just logical. In regards to the & operator I agree that it shouldn't pick the right way to display when concatenating a date value (though in that case it could attempt text conversion with a "DEFAULT" type argument. ..(continued next comment)
    – Erechtheus
    Feb 21, 2020 at 14:44
  • (2/2) The fact that there isn't a set of standardized formats to choose from is what I find dumb. I have the Swedish version of Excel. TEXT(A1,"yyyy-mm-dd") simply doesn't work. TEXT(A1,"ÅÅÅÅ-MM-dd"), however, does. This is easily solved if one could do something like: TEXT(A1,DEFAULT) or say, TEXT(A1,[ISO]yyyy-mm-dd). Problem solved and it's an easy fix that doesn't break any concatenation rules.
    – Erechtheus
    Feb 21, 2020 at 14:46
  • 1
    @starbyone The actual value of the cell has always been decoupled from the cell format. This is very important because if it wasn't the case, then all formulas would become volatile and would have to recalculate each time anything happens anywhere in Excel, which would utterly kill the performance. As for the issue that the TEXT function requires the localized argument, yes, that is a problem and, IMO, an overlook, and a request for a locale-independent TEXT function has been voiced.
    – GSerg
    Feb 21, 2020 at 19:56
6

Another approach

=CONCATENATE("Age as of ", TEXT(TODAY(),"dd-mmm-yyyy"))

This will return Age as of 06-Aug-2013

3

Thanks for the solution !

It works, but in a french Excel environment, you should apply something like

TEXTE(F2;"jj/mm/aaaa")

to get the date preserved as it is displayed in F2 cell, after concatenation. Best Regards

1
2

You can do it this simple way :

A1 = Mahi
A2 = NULL(blank)

Select A2 Right click on cell --> Format cells --> change to TEXT

Then put the date in A2 (A2 =31/07/1990)

Then concatenate it will work. No need of any formulae.

=CONCATENATE(A1,A2)

mahi31/07/1990

(This works on the empty cells ie.,Before entering the DATE value to cell you need to make it as TEXT).

0

I found that for this situation, the simplest solution is to define a Custom number format for the cell containing the date. The format in this case should be:

"This:" mm/dd/yyyy

To set this format:

  1. Right click on the cell
  2. Select Format Cell
  3. Select Number tab (should be displayed by default)
  4. Pick Custom from the Category list
  5. Specify the format in the "Type" field
  6. Press OK

Note: If you really want the preceding text to be picked from a cell, this solution will not work as described.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.