简体   繁体   English

Contenate 同时保持前导零

[英]Contenate while keeping leading zero

I have an Excel spreadsheet in which the date of certain events is stored in three columns: year, month, and day.我有一个 Excel 电子表格,其中某些事件的日期存储在三列中:年、月和日。

Year Month Day
1734 1734 04 04 08 08
1750 1750 11 11 10 10

I set the format of the cell to 'custom' so as to show the leading '0' which I want to maintain.我将单元格的格式设置为“自定义”,以显示我想要保留的前导“0”。 I now want to concatenate the information in these cells so that it shows the date as follows YYYY-MM-DD.我现在想连接这些单元格中的信息,以便它显示日期如下 YYYY-MM-DD。 I'm using this formulate to achieve that:我正在使用这个公式来实现:

=CONCAT(B2, "-", C2, "-", D2)

Annoyingly, however, it doesn't maintain the leading zero (the result is: 1734-4-8 and 1750-11-10, respectively).然而,令人讨厌的是,它不保留前导零(结果分别是:1734-4-8 和 1750-11-10)。 Does anyone know how to concatenate the data from these cells while maintaining the leading zero?有谁知道如何在保持前导零的同时连接这些单元格中的数据?

Cell formatting only changes appearance, but doesn't alter value.单元格格式只改变外观,但不改变价值。 Even if it looks like 04 it still is 4 as value.即使它看起来像 04,它的值仍然是 4。

Use TEXT :使用TEXT

=CONCAT(B2,"-",TEXT(C2,"00"),"-",TEXT(D2,"00"))

or或者

=TEXTJOIN("-",,B2,TEXT(C2,"00"),TEXT(D2,"00"))

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM