在 Excel 中格式化日期

问题描述

如何在 Excel 中轻松格式化“202104”--> 2021/04?

我目前的方法是将原始字符串与“01”连接起来,然后将其更改为日期。但是,我正在寻找一种更有效的格式化方法

谢谢

解决方法

试试这个。

对于文本

=LEFT(A1,4)&"/"&RIGHT(A1,2)

对于日期值

=TEXT(DATEVALUE(LEFT(A1,2)),"YYYY/MM")
,

据我所知,2021/04 在 Excel 中不是有效日期,但 2021/04/01(2021 年四月一日)是。

为了实现这一点,您可以使用以下公式:

=DATE(INTEGER(202104 / 100);MOD(202104;100);1)

地点:

1) INTEGER(202104/100) is the integer division of 202104 by 100,calculating the year.
2) MOD(202104;100) means 202104 modulo 100,in order to calculate the month.
3) 1 means the first day of the month.