如何在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.pswp.cn/news/278585.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278585.shtml
英文地址,請注明出處:http://en.pswp.cn/news/278585.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

git針對已有倉庫或已有文件的初始化操作

git全局配置用戶 git config --global user.name “xxx” git config --global user.email “xxx.cn” 情況1、存在git倉庫 git clone url.git //cd xx //touch README.md //git add README.md //git commit -m "add README" //git push -u origin master情況2、已…

策略模式-Golang實現

目的:根據不同策略來執行對象的相應操作 和工廠模式很像,不同點在于: 工廠模式是傳入參數后創建對象,根據傳入的參數寫邏輯來判斷應該創建什么類型的對象,模式的使用者調用對象統一的方法操作。 策略模式是模式的使用者…

看著手機會讓您暈眩嗎? 禁用動畫

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(中央處理器),是一塊超大規模的集成電路,有很多針腳,是電腦的核心,它是電腦進行運算和控制的核心,處理著各種信息的運算,就像人計算數學題要用頭腦運算一樣。…

【云周刊】第139期:阿里年會黑科技全揭秘:IoT手環、人臉識別驗票、大屏彈幕互動等“十八般武藝”輪番上陣...

摘要:阿里年會黑科技全揭秘:IoT手環、人臉識別驗票、大屏彈幕互動等“十八般武藝”輪番上陣,2017上半年無監督特征學習研究成果匯總,CDN最全學習教程,量子計算會帶來什么樣的革命?更多精彩技術資訊&#xf…

微信小程序之 SideBar(側欄分類)

項目目錄: 模擬數據: utils / data.js function getSData() {var data [{"id": 1,"tree": {"id": 1,"desc": "寶寶奶粉","desc2": null,"level": "level1","log…

騰訊地圖判斷點是否在區域內

鏈接添加幾何計算庫&#xff1a;librariesgeometry xxx為自己的key <script charset"utf-8" src"https://map.qq.com/api/gljs?v1.exp&keyxxx&librariesgeometry"></script>調用 TMap.geometry.isPointInPolygon(position, paths)

如何在線查找成千上萬的免費電子書

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. 您已經有了一個電子書閱讀器(或帶有電子書閱讀軟件的筆…

【SDOI2008】儀仗隊

題面 題解 當$(x,y)$能被看到時&#xff0c;$gcd(x,y)1$&#xff0c; 所以可以求$\sum_{i0}^n\sum_{j0}^n[gcd(x,y)1]$ 或者用歐拉函數 代碼 #include<bits/stdc.h> #define RG register #define clear(x, y) memset(x, y, sizeof(x)); using namespace std;template<…

kbone-cli初始化項目,提示‘模板xx不存在’

取消git代理就好了 git config --global --unset http.proxygit config --global --unset https.proxykbone init my-app跳轉目錄 cd my-app開發小程序 npm run mp開發 Web npm run web 發布 Web npm run build恭喜你! "my-app"項目初始化成功!

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;…

Object defineProperty

Object defineProperty一、簡介1. 屬性表2.互斥性3. get、set的簡單使用二、深入1.定義常量2. Object.preventExtensions() 禁止對象拓展(不可逆)3. Object.seal() 密封(不可逆)4. Object.freeze() 凍結(不可逆)三、應用一、簡介 defineProperty可以詳細的配置一個對象的屬性的…

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;結果如下: 方案一、遷移至新站點 新機站點創建…

js中 給json對象添加屬性和json數組添加元素

json對象&#xff1a; 比如現在有一個json對象為jsonObj&#xff0c;需要給這個對象添加新的屬性newParam&#xff0c;同時給newParam賦值為pre。做法如下&#xff1a; var jsonObj{param1:22,param2 :33}; 現在給jsonObj添加一個新的屬性newParam jsonObj.newParam pre; 新的…

zabbix中php信息缺失之后的安裝

安裝php下enable bcmath和gettext &#xff08;在安裝php時可以添加 --enable-bcmath --enable-gettext&#xff09;1,bcmath安裝方法bcmath這個擴展在php源安裝包壓縮包中都是有的&#xff0c;需要重新編譯一下才能夠支持&#xff1b;cd php-5.2.7/ext/bcmath&#xff08;源…