如何在Microsoft Excel中将文本转换为日期值

excel logo

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.

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

Dates with a full stop separator

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

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

Find and select values in a column

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.”

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

filling out the find and replace values

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

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

Dates with full stops converted to real dates

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.

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

SUBSTITUTE formula to convert text to dates

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

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

Formatting number as a date

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.

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

Dates in the yyyymmdd format

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.

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

Text to Columns button from the Data tab

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格式。

Text to Columns to convert 8 digit numbers to dates

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 the DATE formula with 8 digit numbers

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.

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

Dates stored as text

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)
DATEVALUE function to convert to date values

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)
VALUE function to convert text to numeric values

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/

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/278585.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

看着手机会让您晕眩吗? 禁用动画

Giulio_Fornasar/ShutterstockGiulio_Fornasar /快门Are your phone’s buttery-smooth animations causing motion sickness, eyestrain, or even slow app performance? Those animations are just for looks, and you can disable a lot of them on both iPhone and Androi…

电脑的组成

一、按电脑组成分 1.CPU(中央处理器),是一块超大规模的集成电路,有很多针脚,是电脑的核心,它是电脑进行运算和控制的核心,处理着各种信息的运算,就像人计算数学题要用头脑运算一样。…

微信小程序之 SideBar(侧栏分类)

项目目录: 模拟数据: utils / data.js function getSData() {var data [{"id": 1,"tree": {"id": 1,"desc": "宝宝奶粉","desc2": null,"level": "level1","log…

如何在线查找成千上万的免费电子书

You’ve got an ebook reader (or a laptop or netbook with ebook reading software) now you just need some free books to put it to good use. Read on as we show you the best places to score free books online. 您已经有了一个电子书阅读器(或带有电子书阅读软件的笔…

Spring Bean默认配置为单实例 Spring Bean生命周期

2019独角兽企业重金招聘Python工程师标准>>> Spring 的Bean默认的是单例的. 如果不想单例需要如下配置&#xff1a; <bean id"user" class"..." scope"singleton"/> scope"singleton"就是配置这个bean是单例的&#…

minecraft服务器_如何启动自己的Minecraft服务器进行多人游戏

minecraft服务器If you’ve played Minecraft, then it’s easy to see how much fun it can be. Running your own server lets you bring all of your friends into the same game, and you can play with rules you get to make or break. It’s the ultimate in an already…

Spring Boot 2.x(六):优雅的统一返回值

目录 为什么要统一返回值ReturnVOReturnCode使用ReturnVO使用AOP进行全局异常的处理云撸猫公众号为什么要统一返回值 在我们做后端应用的时候&#xff0c;前后端分离的情况下&#xff0c;我们经常会定义一个数据格式&#xff0c;通常会包含code&#xff0c;message&#xff0c;…

jhope代码分析以及网站结构

如下图所示&#xff0c;为Extjs部分代码提供的网页结构&#xff1a;网站看上去本来是这样的前端采用ExtJS&#xff0c;与后台的SpringMVCSpringHibernate进行数据交互。之前分析过登录的过程&#xff0c;不赘述在loginController处理登录返回结果的最后&#xff0c;如下语句也就…

Ubuntu下Authentication token manipulation error或者Authentication Failure解决办法

在Ubuntu18.04使用以下命令出现以下错误: 用passwd为新建用户或者root添加密码:Authentication token manipulation error 切换root用户出现Authentication Failure. 网上出现了大致两种方法: 第一种&#xff1a;用户文件和密码文件被保护&#xff0c;用chattr命令移除保护即可…

初学者:如何使用虚拟PC将Windows 7安装到虚拟机

Continuing in our series covering how to use Virtual PC, this week we’ll be showing you how to install Windows 7 into a virtual machine. It’s a very simple process, but here’s the step-by-step guide for beginners. 继续我们的系列文章&#xff0c;介绍如何使…

arcgis本地服务快速迁移到新机

情景 在本机或服务器发布了几十、几百个gis服务&#xff0c;当换电脑或者换服务器时不可能挨个找源文件重新发布服务&#xff0c;于是就想着既然是本地文件&#xff0c;一定可以拷贝过去的&#xff0c;经过一番搜索&#xff0c;结果如下: 方案一、迁移至新站点 新机站点创建…

极客大佬用什么电脑_极客特惠:笔记本电脑,高清电视和免费应用

极客大佬用什么电脑If you love new gear but not high prices then we’ve got some deals for you; grab some deeply discounted laptops, monitors and HDTVs, and free mobile apps in this week’s Geek Deals roundup. 如果您喜欢新设备&#xff0c;但不喜欢高价&#x…

ppt插入html(用office而不是wps)

最近新get到的技能&#xff0c;在ppt里面插入html&#xff01;注意要用 Microsoft Office PowerPoint 才行&#xff0c;而不是wps&#xff0c;一定要先安装Microsoft Office PowerPoint再执行以下操作。 1、修改注册表的值&#xff0c;才能在PowerPoint中插入 Microsoft Web B…

如何使用SkyDrive的25 GB作为映射驱动器以方便访问

SkyDrive is an online storage system included in Windows Live, which gives you 25 GB of space that you can sync to your desktop. Here’s how to connect it to your Windows 7 computer as a mapped drive. SkyDrive是Windows Live中包含的一个在线存储系统&#xff…

SpringBoot+Mybatis 框架之 @SelectProvider注解方式搭建

之前搭建了Select标签来做SringBootMybatis的集成。这次使用SelectProvider标签的方式搭建一次。 一、搭建SpringBoot的项目 https://start.spring.io/自己配置SpringBoot的项目&#xff0c;点击“Generate Project”按钮就可以下载下来一个配置好的SpringBoot项目。 二、项目结…

从购买域名到nginx,flask搭建自己的网站

搭建一个只属于自己的网站? 一、注册域名&#xff08;可选*&#xff09; 1.注册阿里云账号 网址&#xff1a;登录&#xff08;注册&#xff09; 2.购买域名&#xff1a;阿里云域名注册 有一元域名、免费域名等。 购买过程中需要创建信息模板&#xff08;必须完成邮箱真实…

alexa语音实现_如何通过语音删除Alexa录音

alexa语音实现Amazon亚马孙Amazon is rolling out new privacy features today for Alexa. In addition to an educational “privacy hub,” the company lets you delete your stored recordings by voice. But it’s off by default; you’ll need to flip a switch. 亚马逊…

用scrapy框架写爬虫

爬虫可以发送给引擎的两种请求&#xff1a; # 1、url&#xff1a;# &#xff08;爬虫&#xff09;yield scrapy.Request -> 引擎 -> 调度器&#xff08;发送给调度器入队&#xff09; -> 引擎&#xff08;调度器出队请求于引擎&#xff09;# -> 下载器&#xff08;…

audacity_如何在Audacity中快速编辑多个文件

audacityGot a bunch of files that need to be edited the same way? You can automate the process to save time and effort using Audacity’s Chain feature and modify tons of files at the same time. 有一堆需要以相同方式编辑的文件&#xff1f; 您可以使用Audacity…

通过api管理grafana

1. 生成api key 参考&#xff1a; http://docs.grafana.org/http_api/auth/ 2.点击添加后&#xff0c;生成了个获取一个deshboards的api样例 3.放到linux上运行测试&#xff0c;结果成功返回。 4. 有些api并不支持使用api key 来连接&#xff0c;如下图中的搜索用户接口&#x…