Analysis of business data often requires working with date values in Excel to answer questions such as “how much money did we make today” or “how does this compare to the same day last week?” And that can be hard when Excel doesn’t recognize the values as dates.

对业务数据进行分析通常需要使用Excel中的日期值来回答诸如“我们今天赚了多少钱”或“与上周同一天相比有多少钱?”之类的问题。 当Excel无法将值识别为日期时,这可能会很难。

Unfortunately, this is not unusual, especially when multiple users are typing this information, copying and pasting from other systems and importing from databases.

不幸的是,这并不罕见,尤其是当多个用户键入此信息,从其他系统复制和粘贴以及从数据库导入时。

In this article, we will describe four different scenarios and the solutions to convert the text to date values.

在本文中,我们将描述四种不同的情况以及将文本转换为日期值的解决方案。

包含句号/日期的日期 (Dates that Contain a Full Stop/Period)

Probably one of the most common mistakes beginners make when typing dates into Excel is doing so with the full stop character to separate the day, month, and year.

初学者在Excel中键入日期时可能犯的最常见错误之一是使用句号分隔日期,月份和年份。

Excel will not recognize this as a date value and will go ahead and store it as text. However, you can solve this problem with the Find and Replace tool. By replacing the full stops with slashes (/), Excel will automatically identify the values as dates.

Excel不会将其识别为日期值,并将继续将其存储为文本。 但是,您可以使用“查找和替换”工具解决此问题。 通过用斜杠(/)代替句号,Excel将自动将值标识为日期。

Select the columns on which you want to perform the find and replace.

选择要在其上执行查找和替换的列。

Click Home > Find & Select > Replace—or press Ctrl+H.

单击主页>查找并选择>替换-或按Ctrl + H。

In the Find and Replace window, type a full stop (.) in the “Find what” field and a slash (/) in the “Replace with” field. Then, click “Replace All.”

在“查找和替换”窗口中,在“查找内容”字段中键入句号(。),在“替换为”字段中键入斜杠(/)。 然后,单击“全部替换”。

All full stops are converted to slashes and Excel recognizes the new format as a date.

所有句号都将转换为斜杠,并且Excel会将新格式识别为日期。

If your spreadsheet data is regularly changing, and you want an automated solution for this scenario, you could use the SUBSTITUTE function.

如果您的电子表格数据有规律地更改,并且您想要针对这种情况的自动化解决方案,则可以使用SUBSTITUTE函数。

=VALUE(SUBSTITUTE(A2,".","/"))

The SUBSTITUTE function is a text function, so cannot convert it to a date on its own. The VALUE function will convert the text value to a numeric value.

SUBSTITUTE函数是文本函数,因此无法自行将其转换为日期。 VALUE函数会将文本值转换为数字值。

The results are shown below. The value needs to be formatted as a date.

结果如下所示。 该值需要格式化为日期。

You can do this using the “Number Format” list on the “Home” tab.

您可以使用“主页”选项卡上的“数字格式”列表执行此操作。

The example here of a full stop delimiter is typical. But you can use the same technique to replace or substitute any delimiter character.

这里以句点定界符为例。 但是您可以使用相同的技术来替换或替换任何定界符。

转换yyyymmdd格式 (Converting the yyyymmdd Format)

If you receive dates in the format shown below, it will require a different approach.

如果您收到以下所示格式的日期,则将需要使用其他方法。

This format is quite standard in technology as it removes any ambiguity about how different countries store their date values. However, Excel will not initially understand it.

这种格式在技术上非常标准,因为它消除了有关不同国家/地区如何存储其日期值的任何歧义。 但是,Excel最初不会理解它。

For a quick manual solution, you could use Text to Columns.

对于快速的手动解决方案,您可以使用Text to Columns 。

Select the range of values you need to convert and then click Data > Text to Columns.

选择您需要转换的值范围,然后单击数据>文本到列。

The Text to Columns wizard appears. Click “Next” on the first two steps so that you are at step three, as shown in the image below. Choose Date and then select the date format being used in the cells from the list. In this example, we are dealing with a YMD format.

出现“文本到列”向导。 在前两个步骤中单击“下一步”,以便进入第三步,如下图所示。 选择日期,然后从列表中选择单元格中使用的日期格式。 在此示例中,我们正在处理YMD格式。

If you would like a formula solution, then you could use the Date function to construct the date.

如果需要公式解决方案,则可以使用Date函数构造日期。

This would be used alongside the text functions Left, Mid and Right to extract the three parts of a date (day, month, year) from the cell contents.

这将与文本函数Left,Mid和Right一起使用,以从单元格内容中提取日期的三部分(日,月,年)。

The formula below shows this formula using our sample data.

以下公式使用我们的样本数据显示了此公式。

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

Using either of these techniques, you can convert any eight-digit number value. For example, you might receive the date in a ddmmyyyy format or a mmddyyyy format.

使用这些技术中的任何一种,都可以转换任何八位数字的值。 例如,您可能会以ddmmyyyy格式或mmddyyyyy格式接收日期。

DATEVALUE和VALUE函数 (DATEVALUE and VALUE Functions)

Sometimes the problem is not caused by a delimiter character but has an awkward date structure simply because it is stored as text.

有时问题不是由定界符引起的,而是仅由于以文本形式存储而具有笨拙的日期结构。

Below is a list of dates in a variety of structures, but they are all recognizable to us as a date. Unfortunately, they have been stored as text and need converting.

以下是各种结构中的日期列表,但我们都可以将它们识别为日期。 不幸的是,它们已被存储为文本并且需要转换。

For these scenarios, it is easy to convert using a variety of techniques.

对于这些情况,可以使用多种技术轻松进行转换。

For this article, I wanted to mention two functions to handle these scenarios. They are DATEVALUE and VALUE.

对于本文,我想提到两个函数来处理这些情况。 它们是DATEVALUE和VALUE。

The DATEVALUE function will convert text into a date value (probably saw that coming), while the VALUE function will convert text into a generic number value. The differences between them are minimal.

DATEVALUE函数会将文本转换为日期值(可能已经看到了),而VALUE函数会将文本转换为通用数字值。 它们之间的差异很小。

In the image above, one of the values contains time information as well. And that will be a demonstration of the functions’ minor differences.

在上图中,其中一个值也包含时间信息。 这将演示功能的微小差异。

The DATEVALUE formula below would convert each one to a date value.

下面的DATEVALUE公式会将每个数字转换为日期值。

=DATEVALUE(A2)

Notice how the time was removed from the result in row 4. This formula strictly returns just the date value. The result will still need to be formatted as a date.

请注意,时间是如何从第4行的结果中删除的。此公式严格只返回日期值。 结果仍然需要格式化为日期。

The following formula uses the VALUE function.

以下公式使用VALUE函数。

=VALUE(A2)

This formula will produce the same results except for in row 4, where the time value is also maintained.

该公式将产生相同的结果,但第4行中的时间值也保持不变。

The results can then be formatted as date and time, or as a date to hide the time value (but not remove).

然后可以将结果格式化为日期和时间,或格式化为隐藏时间值(但不能删除)的日期。

翻译自: https://www.howtogeek.com/415246/how-to-convert-text-to-date-values-in-microsoft-excel/

如何在Microsoft Excel中将文本转换为日期值相关推荐

  1. EXCEL中将时间戳转换为日期格式

    EXCEL中将时间戳转换为日期格式 从linux系统中获取的时间戳信息通常为s,将其转换的公式为: =TEXT((E1+83600)/86400+70365+19,"yyyy-mm-dd h ...

  2. 字符转char android,android – 如何在kotlin语言中将char转换为ascii值

    我正在使用kotlin开发一个 android应用程序,我需要将字符串字符转换为其ASCII值, fun tryDiCript(cypher: String) :String { var cypher ...

  3. 在Excel中将文本转换为数字

    问题:如何将填充有字符数字的单元格转换为数值,以便可以使用Excel数学公式中的值. ( Question: How do I convert cells filled with character ...

  4. linux shell转换成时间,如何在Bash中将时间戳转换为日期?

    如何在Bash中将时间戳转换为日期? 我需要一个将Unix时间戳转换为日期的shell命令或脚本. 输入可以来自第一个参数或来自stdin,允许以下使用模式: ts2date 1267619929 和 ...

  5. 替代微软txt文本编辑器_如何在Microsoft Excel中向对象添加替代文本

    替代微软txt文本编辑器 Alternative text (alt text) allows screen readers to capture the description of an obje ...

  6. 在Java中将字符串转换为日期,将日期转换为字符串

    Sometimes we have to Convert String to Date in java program or convert Date to String in a different ...

  7. mysql查询出的数据转换为数字,关于sql:在MySQL查询中将文本转换为数字

    是否可以在MySQL查询中将文本转换为数字? 我有一列带有标识符的列,该标识符由名称和数字组成,格式为"名称-数字". 该列具有VARCHAR类型. 我想根据数字(具有相同名称的行 ...

  8. Microsoft Excel 教程:如何在 Excel 中将文本拆分为不同的列?

    欢迎观看 Microsoft Excel 教程,小编带大家学习 Microsoft Excel 的使用技巧,了解如何在 Excel 中使用"文本分列向导 "将文本拆分为不同的列. ...

  9. 计算机中日期函数的应用,解读:使用EXCEL中的TEXT函数将文本转换为日期

    在EXCEL中,文本的功能是将各种形式的值转换为特定格式的文本.函数如下:= Text(要转换的单元格,特定格式的字符串) 例如:将单元格A1的值设置为1,我们要将A1的内容转换为001格式,可以使用 ...

最新文章

  1. shell基础语法以及监控进程不存在重启
  2. 【 MATLAB 】randn,rand,randi 之间的区别?
  3. bat 快速切换路径
  4. numpy中的ogrid
  5. openresty 前端开发进阶一之http后端
  6. 在嵌套使用if语句时,C语言规定else总是什么?
  7. 程序员,35岁就可能被替换的职业,遇到好的领导多么重要
  8. 如何释放hdfs中的续租_装修中甲醛如何高效释放
  9. ZeroClipboard插件——复制到剪切板
  10. 学成在线-处理常见视频格式avi,mp4,mov,rmvb,flv
  11. ABP框架实战 1.基础信息维护
  12. 《三体1》6.射手和农场主
  13. android 360度视频播放器,Android开发VR实战之播放360度全景视频
  14. 41家对中国市场依赖度最高(依营收占比计算)的美国公司
  15. Python编程PTA题解大全——索引
  16. 类型数组HTML5 中的新数组
  17. 五千年中国富豪排行榜(组图)
  18. c#NAudio 录音功能实现
  19. oracle和勇士,坑与“借鉴”,都是KPI逼的?
  20. label smooth/mixup——深度学习中的一种防止过拟合方法

热门文章

  1. 程序人生:什么是“对用户友好”
  2. C#实现简体繁体转换代码示例
  3. 语言筛选法选素数怎么解决输出超限_论文深耕 | 什么时候才能把文献看完?——论文的正确筛选、阅读顺序...
  4. 不生效 设置了viewport_配置viewport
  5. 线程条件控制实现线程的同步
  6. 5g的负面影响_设计系统的实施是否会对早期概念产生负面影响?
  7. 最全 JavaScript Array 方法 详解
  8. 使用 Solid 私有化存储 IPFS 文件哈希值
  9. https://blog.csdn.net/cscscscsc/article/details/50
  10. Gartner认为安全性将取代成本和敏捷性成为政府部门采用云服务的首要原因