在 Excel 中连接日期与字符串
我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
不知道这是否是最好的方法,但我会这样做:
这应该将您的日期格式化为您想要的字符串。
编辑:您看到的那个有趣的数字是 1899 年 12 月 31 日与您的日期之间的天数。这就是 Excel 存储日期的方式。
Don't know if it's the best way but I'd do this:
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.
这是日期的数字表示形式。当你从这样的公式中引用日期时,你会得到这样的结果。
您必须这样做:
这里最大的问题是格式说明符与区域设置相关。如果使用不同本地化的 Excel 打开文件,它将无法工作/产生不预期的结果。
现在,您可以有一个用户定义的函数:
然后
但是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:
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:
and then
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.
另一种方法
这将返回
截至 2013 年 8 月 6 日的年龄
Another approach
This will return
Age as of 06-Aug-2013
感谢您的解决方案!
它可以工作,但在法语 Excel 环境中,您应该应用类似的方法
来保留连接后 F2 单元格中显示的日期。
此致
Thanks for the solution !
It works, but in a french Excel environment, you should apply something like
to get the date preserved as it is displayed in F2 cell, after concatenation.
Best Regards
你可以用这个简单的方法来做到这一点:
选择A2 右键单击单元格 --> 设置单元格格式 -->更改为 TEXT
然后将日期放入 A2 (A2 =31/07/1990)
然后连接即可。不需要任何公式。
(这适用于空单元格,即,在将日期值输入单元格之前,您需要将其设置为文本)。
You can do it this simple way :
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.
(This works on the empty cells ie.,Before entering the DATE value to cell you need to make it as TEXT).
我发现对于这种情况,最简单的解决方案是为包含日期的单元格定义自定义数字格式。本例中的格式应为:
要设置此格式:
注意:如果您确实希望从单元格中选取前面的文本,则此解决方案将无法按所述工作。
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:
To set this format:
Note: If you really want the preceding text to be picked from a cell, this solution will not work as described.