简体   繁体   English

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

[英]How do I convert date-time to date in Excel?

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 . 但它得到的结果是2/28/2017
YYYY and MM is correct, not sure why date is incorrect and where is 28 coming from. YYYYMM是正确的,不确定日期为何不正确以及28来源。

Your "RIGHT(B2,2)" formula is getting the last 2 digits of your DateTime, so: 您的"RIGHT(B2,2)"公式正在获取DateTime的最后两位数字,因此:

201703020921 00 201703020921 00

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 当您将其放入公式=Date(2017,3,0)您将获得=Date(2017,3,0)

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! 谢谢!

正确的公式是:

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

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

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