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.
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.
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.
Step 2: Next,click theth column of the column where you want to extract theDayvalue a cell.
Step 3: Now press theCTRL Vkey to paste the data.
Step 4:Right-clickanywhere in the selected range of cells and click the button named "Settings"Cell" option.
Step 5: In the "SetCellFormat" window, first click "Number"Tab. Next, underCategoryOptions, clickCustomizeOptions.
Now, under theTypefield, 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 theOKbutton after completion.
If you wish to display full working days then you need to providedddd instead ofunder theTypefield ddd.Makes the sample data displayed asTuesday.
Step 6: That’s it. You have successfully extracted a date value from a date value, it's that simple.
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 calledText().
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")
with the desired cell ID that has the date value. Additionally,dddwill give the date in 3-letter format. For example,Tuesday.
If you want a fully formatted date value, such as
Tuesday, then your formula should haveddddas its first Two parameters instead ofddd.
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.
如果您想在列中应用公式,只需单击并拖动单元格右下角的小正方形。
第 3 步:您现在拥有 Excel 工作表中所有日期值的日期值。
与本文中列出的前 2 种方法相比,此方法相对复杂。此方法通过结合 2 个公式函数即Choose()和Weekday()从日期值中提取日期值。然而,这种方法有点令人讨厌,但我们喜欢令人讨厌的东西。希望你也这样做。
第 1 步:双击Day 列的第一个单元格以编辑其内容。将以下公式复制并粘贴到其上。
=CHOOSE(WEEKDAY(A3),"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY")
公式中的A3必须替换为具有要从中提取日期值的日期值的单元格的单元格 ID。
上面公式中首先解决的部分是WEEKDAY(A3)。Weekday 函数将日期作为参数,并以整数形式返回工作日。默认情况下,该函数假定一周从星期日到星期六。所以,如果这是一个正常的场景,你可以只给这个函数一个参数。在这个公式中,我只给出了一个参数 A3,它是包含我需要从中查找日期的日期的单元格的单元格 ID。但是,如果您的一周从星期一开始,那么您需要为您的函数再提供一个参数,使其成为 WEEKDAY(A3,2)。因此,在这种情况下,您的最终公式将如下所示。
=CHOOSE(WEEKDAY(A3,2),"SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY")
因此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")
第 2 步:如果您按Enter键或单击其他任何位置,您可以看到日期值已成功填充到您选择的单元格中。
要将公式应用于列中的所有单元格,请单击单元格角落的小方形图标并将其向下拖动。
第 3 步:该公式现在已成功应用于所有单元格,并且现在将日期值填充到整个列中。
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!