简体   繁体   English

Excel 日期月日年转换

[英]Excel Date month day year conversion

I have dates in the format:我有以下格式的日期:

Monday, March 25 2019 2019 年 3 月 25 日,星期一

Wednesday, September 25 2019 2019 年 9 月 25 日,星期三

I would like to convert them to DD/MM/YY format (ie 25/03/2019)我想将它们转换为 DD/MM/YY 格式(即 25/03/2019)

I have tried the following excel formula:我尝试了以下 excel 公式:

DATEVALUE(MID(B2,FIND(", ",B2)+6,2)&"-"&MID(B2,FIND(", ",B2)+2,3)&"-"&RIGHT(B2,4)) DATEVALUE(MID(B2,FIND(", ",B2)+6,2)&"-"&MID(B2,FIND(", ",B2)+2,3)&"-"&RIGHT(B2,4) )

does anyone know where I have made an error in this formula or an alternative?有谁知道我在这个公式或替代方案中哪里出错了?

The way you find your day is incorrect, you search for ", " which is the only unique character in string, but then add 6 to that to get your date value (25) this won't work because the month names can be longer.您找到日期的方式不正确,您搜索", " ,这是字符串中唯一的唯一字符,但随后将 6 添加到该字符串中以获得您的日期值(25)这将不起作用,因为月份名称可能更长. This formula will work:这个公式将起作用:

=DATEVALUE(LEFT(RIGHT(B2,7),2)&"-"&MID(B2,FIND(", ",B2)+2,3)&"-"&RIGHT(B2,4))

It takes the last 7 characters from the string (day and year, always same size assuming a leading zero in the date) and gets the first two numbers from it, matching your day.它从字符串中获取最后 7 个字符(日期和年份,始终相同大小,假设日期前导零)并从中获取前两个数字,与您的日期匹配。

EDIT Tested without a leading zero in the date, this seems to work as well.编辑在日期没有前导零的情况下进行了测试,这似乎也有效。

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

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