在 Excel 中连接日期与字符串

发布于 2024-11-15 18:22:42 字数 258 浏览 2 评论 0原文

我的 Excel 中有两个单元格。一个有字符串,另一个有日期。在第三个单元格中,我想将日期和字符串放在一起。例如:

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

我希望 A3 为:

This 03/03/1982

当我尝试将其放入 A3 公式中时: = A1 & A2 它返回一些有趣的日期数值,但没有给我文字日期。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

月下客 2024-11-22 18:22:42

不知道这是否是最好的方法,但我会这样做:

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

这应该将您的日期格式化为您想要的字符串。

编辑:您看到的那个有趣的数字是 1899 年 12 月 31 日与您的日期之间的天数。这就是 Excel 存储日期的方式。

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.

◇流星雨 2024-11-22 18:22:42

这是日期的数字表示形式。当你从这样的公式中引用日期时,你会得到这样的结果。

您必须这样做:

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

这里最大的问题是格式说明符与区域设置相关。如果使用不同本地化的 Excel 打开文件,它将无法工作/产生不预期的结果。

现在,您可以有一个用户定义的函数:

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

然后

= A1 & AsDisplayed(A2)

但是Excel中有一个错误(功能?),因为.Text属性突然在计算周期的某些阶段不可用,并且您的公式显示 #VALUE 而不是应有的内容。

也就是说,无论哪种方式都不好。

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.

寂寞清仓 2024-11-22 18:22:42

另一种方法

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

这将返回
截至 2013 年 8 月 6 日的年龄

Another approach

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

This will return
Age as of 06-Aug-2013

佞臣 2024-11-22 18:22:42

感谢您的解决方案!

它可以工作,但在法语 Excel 环境中,您应该应用类似的方法

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

来保留连接后 F2 单元格中显示的日期。
此致

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

清风不识月 2024-11-22 18:22:42

你可以用这个简单的方法来做到这一点:

A1 = 鲯鱼
A2 = NULL(空白)

选择A2 右键单击​​单元格 --> 设置单元格格式 -->更改为 TEXT

然后将日期放入 A2 (A2 =31/07/1990)

然后连接即可。不需要任何公式。

=连接(A1,A2)

mahi31/07/1990

(这适用于空单元格,即,在将日期值输入单元格之前,您需要将其设置为文本)。

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).

爱人如己 2024-11-22 18:22:42

我发现对于这种情况,最简单的解决方案是为包含日期的单元格定义自定义数字格式。本例中的格式应为:

"This:" mm/dd/yyyy

要设置此格式:

  1. 右键单击单元格
  2. 选择单元格格式
  3. 选择数字选项卡(默认情况下应显示)
  4. 从类别列表中选择自定义
  5. 在“类型”字段中指定格式
  6. 按确定

注意:如果您确实希望从单元格中选取前面的文本,则此解决方案将无法按所述工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文