如何在Excel中将日期时间转换为日期?

时间:2021-12-22 15:59:53

20170302092100 should be 2017-03-02.

20170302092100应该是2017-03-02。

Have used this formula:

使用过这个公式:

=DATE(LEFT(B2,4),MID(B2,5,2),RIGHT(B2,2))

but it is getting the result as 2/28/2017.
YYYY and MM is correct, not sure why date is incorrect and where is 28 coming from.

但它的结果是2/28/2017。 YYYY和MM是正确的,不确定为什么日期不正确,28来自哪里。

2 个解决方案

#1


3  

Your "RIGHT(B2,2)" formula is getting the last 2 digits of your DateTime, so:

您的“右(B2,2)”公式是获取DateTime的最后2位数,因此:

20170302092100

Running your "LEFT()", "RIGHT()" AND "MID()", you get: 2017 3 0

运行你的“LEFT()”,“RIGHT()”和“MID()”,你得到:2017 3 0

And when you put that into a formula =Date(2017,3,0) you'll get 2/28/2017

当你把它放入公式=日期(2017,3,0)时,你会得到2/28/2017

The correct formula would be: =DATE(LEFT(B2,4),MID(B2,5,2),MID(B2,7,2))

正确的公式是:= DATE(LEFT(B2,4),MID(B2,5,2),MID(B2,7,2))

Thanks!

#2


0  

The correct formula is:

正确的公式是:

=DATE(LEFT(B2,4),MID(B2,5,2),MID(B2,7,2))

#1


3  

Your "RIGHT(B2,2)" formula is getting the last 2 digits of your DateTime, so:

您的“右(B2,2)”公式是获取DateTime的最后2位数,因此:

20170302092100

Running your "LEFT()", "RIGHT()" AND "MID()", you get: 2017 3 0

运行你的“LEFT()”,“RIGHT()”和“MID()”,你得到:2017 3 0

And when you put that into a formula =Date(2017,3,0) you'll get 2/28/2017

当你把它放入公式=日期(2017,3,0)时,你会得到2/28/2017

The correct formula would be: =DATE(LEFT(B2,4),MID(B2,5,2),MID(B2,7,2))

正确的公式是:= DATE(LEFT(B2,4),MID(B2,5,2),MID(B2,7,2))

Thanks!

#2


0  

The correct formula is:

正确的公式是:

=DATE(LEFT(B2,4),MID(B2,5,2),MID(B2,7,2))