Home> Common Problem> body text

How to extract date value from date value in Microsoft Excel

WBOY
Release: 2023-05-02 19:10:05
forward
8661 people have browsed it

In some cases you may want to extract a date from a date. Let's say your date is 27/05/2022 and your Excel sheet should be able to tell you that today is Friday. If this could be achieved, it could find applications in many situations, such as finding workdays for items, school assignments, etc.

In this article, we have come up with 3 different solutions that you can use to easily extract date values from date values and automatically apply them to the entire column. Hope you enjoyed this article.

Example Scenario

We have a column namedDatewhich contains date values. The other columnDay is empty and its value will be filled by calculating the date value from the corresponding date value in theDatecolumn.

Solution 1: Use the Format Cells option

This is the simplest of all methods as it does not involve any formulas.

Step 1: Copy the entire date value from column 1 (Datecolumn).

You canselect the entire data,right-clickand select the "Copy"option, or you canselect the data# After ## simply press theCTRL Ckey.

如何从 Microsoft Excel 中的日期值中提取日期值

Step 2: Next,click theth column of the column where you want to extract theDayvalue a cell.

如何从 Microsoft Excel 中的日期值中提取日期值

Step 3: Now press theCTRL Vkey to paste the data.

如何从 Microsoft Excel 中的日期值中提取日期值

Step 4:Right-clickanywhere in the selected range of cells and click the button named "Settings"Cell" option.

如何从 Microsoft Excel 中的日期值中提取日期值

Step 5: In the "SetCellFormat" window, first click "Number"Tab. Next, underCategoryOptions, clickCustomizeOptions.

Now, under the

Typefield, enterddd.Under theSamplesection just above the Typefield you will be able to view sample data. Because we gaveddd, the example data displays weekday in 3-letter format, which in the following example isTue.

Click the

OKbutton after completion.

如何从 Microsoft Excel 中的日期值中提取日期值

If you wish to display full working days then you need to provide

dddd instead ofunder theTypefield ddd.Makes the sample data displayed asTuesday.

如何从 Microsoft Excel 中的日期值中提取日期值

Step 6: That’s it. You have successfully extracted a date value from a date value, it's that simple.

如何从 Microsoft Excel 中的日期值中提取日期值

Solution 2: Use the TEXT formula function

This is another simple method that you can use to quickly extract date values from date values . This method uses a formula function called

Text().

Step 1:Double-clickthe first cell of the column where you want to extract the date value. Now, copy and paste the following formulaonto it.

=TEXT(A3,"ddd")
Copy after login
You must

replace A3

with the desired cell ID that has the date value. Additionally,dddwill give the date in 3-letter format. For example,Tuesday.

如何从 Microsoft Excel 中的日期值中提取日期值If you want a fully formatted date value, such as

Tuesday

, then your formula should haveddddas its first Two parameters instead ofddd.

如何从 Microsoft Excel 中的日期值中提取日期值

Step 2

: If you press elsewhere or press theEnterkey, you can see that the formula has been successfully applied, And now the date value is extracted successfully.

如果您想在列中应用公式,只需单击并拖动单元格右下角小正方形

如何从 Microsoft Excel 中的日期值中提取日期值

第 3 步:您现在拥有 Excel 工作表中所有日期值的日期值。

如何从 Microsoft Excel 中的日期值中提取日期值

解决方案 3:通过组合 CHOOSE 和 WEEKDAY 公式函数

与本文中列出的前 2 种方法相比,此方法相对复杂。此方法通过结合 2 个公式函数即Choose()Weekday()从日期值中提取日期值。然而,这种方法有点令人讨厌,但我们喜欢令人讨厌的东西。希望你也这样做。

第 1 步双击Day 列的第一个单元格以编辑其内容。将以下公式复制并粘贴到其上。

=CHOOSE(WEEKDAY(A3),"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY")
Copy after login

公式中的A3必须替换为具有要从中提取日期值的日期值的单元格的单元格 ID。

如何从 Microsoft Excel 中的日期值中提取日期值

公式说明

上面公式中首先解决的部分是WEEKDAY(A3)Weekday 函数将日期作为参数,并以整数形式返回工作日。默认情况下,该函数假定一周从星期日到星期六。所以,如果这是一个正常的场景,你可以只给这个函数一个参数。在这个公式中,我只给出了一个参数 A3,它是包含我需要从中查找日期的日期的单元格的单元格 ID。但是,如果您的一周从星期一开始,那么您需要为您的函数再提供一个参数,使其成为 WEEKDAY(A3,2)。因此,在这种情况下,您的最终公式将如下所示。

=CHOOSE(WEEKDAY(A3,2),"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY")
Copy after login

因此WEEKDAY()函数以数字格式返回一周中的星期几。也就是说,如果这一天是Tuesday,那么WEEKDAY() 将返回 3

CHOOSE()函数根据其第一个参数从其参数列表中返回一个字符串。

CHOOSE()函数可以有很多参数。第一个参数是索引号。索引号后面的参数是需要根据索引号选取的字符串。例如,如果 CHOOSE() 函数的第一个参数是 1 ,那么 CHOOSE()函数返回列表中的第一个字符串。

所以在这个特定的场景中,WEEKDAY()函数返回3作为它的返回值。现在CHOOSE()函数将这个3作为它的第一个参数。并根据此索引值返回列表中的第三个字符串。所以CHOOSE()函数最终会返回TUESDAY

如果您想返回天的短格式,您可以在主公式中进行调整,如下所示。

=CHOOSE(WEEKDAY(A3,2),"Sun","Mon","Tue","Wed","Thu","Fri","Sat")
Copy after login

第 2 步:如果您按Enter键或单击其他任何位置,您可以看到日期值已成功填充到您选择的单元格中。

要将公式应用于列中的所有单元格,请单击单元格角落的小方形图标并将其向下拖动

如何从 Microsoft Excel 中的日期值中提取日期值

第 3 步:该公式现在已成功应用于所有单元格,并且现在将日期值填充到整个列中。

如何从 Microsoft Excel 中的日期值中提取日期值

The above is the detailed content of How to extract date value from date value in Microsoft Excel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yundongfang.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!