Excel DATEVALUE 函数独立于国际设置 [英] Excel DATEVALUE function independent of international settings

查看:20
本文介绍了Excel DATEVALUE 函数独立于国际设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Excel 工作簿中,我从另一个(文本)源复制了一些日期信息.为了能够对这些日期进行计算,我使用了函数DATEVALUE".

In my Excel workbook, I copy some date information from another (text) source. To be able to do calculations with these dates, I use the function "DATEVALUE".

示例:单元格 A1 包含文本 20 february 2014,单元格 B1 包含公式 =DATEVALUE(A1).这按预期工作:我得到了自 1-1-1900 以来的天数,我可以用任何可以想象的日期表示法显示它.
到目前为止没有问题.尽管这不是英语中的典型日期表示法,但 DATEVALUE 将 february 识别为月份名称并采取相应措施.

Example: cell A1 contains the text 20 february 2014, cell B1 contains the formula =DATEVALUE(A1). This works as expected: I get the number of days since 1-1-1900, which I can display in any date notation imaginable.
No problem so far. Even through this is not a typical date notation in the English language, DATEVALUE recognizes february as the month name and acts accordingly.

现在,当我在具有不同国际设置(Windows 7:控制面板 -> 区域和语言 -> 格式)的计算机上打开此工作簿时,单元格 B1 会出现 #VALUE 错误.仅当我将 A1 中的文本更改为 20 februari 2014 (荷兰日期字符串,根据该 PC 上的国际设置)时,DATEVALUE 给出的结果与以前相同.

Now, when I open this workbook on a computer with different international settings (Windows 7: Control panel -> Region and language -> Formats), cell B1 gives a #VALUE error. Only when I change the text in A1 to 20 februari 2014 (Dutch date string, in accordance with the international settings on that PC), DATEVALUE gives the same result as before.

显然,DATEVALUE 使用国际设置将字符串转换为日期.

Apparently, the DATEVALUE uses the international settings to convert from the string to a date.

有什么办法可以防止这种情况发生,换句话说:

Is there some way to prevent this, in order words:

  • 为了让 Excel 明白 A1 中的字符串是用英文写的,不管 PC 上的国际设置是什么
  • 并将此字符串转换为日期,以便随后用于计算?

推荐答案

你可以试试这个公式:

=DATE(RIGHT(A1;4);MATCH(MID(A1;4;3);{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"};0);LEFT(A1;2))

日期总是按年、月、日的顺序接受参数

Date admits arguments always in the order year, month, day

我承认日值始终是 2 位数字.

I admit that day values are always 2 digits.

如果你不介意写下月份的缩写.在一个范围内,你可以得到一个更短的公式.

If you dont mind to write the months abrev. in a range then you can get a much more shorter formula.

根据您的区域设置,您可能需要替换字段分隔符;"由,"

Depending on your regional settings you may need to replace field separator ";" by ","

这篇关于Excel DATEVALUE 函数独立于国际设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆