How to use DATEDIF() in Excel function learning
This article will introduce you to the DATEDIF function! The DATEDIF function can not only be used to calculate age, length of service, length of service salary, and project cycle, but can also be used to make birthday countdown reminders, project completion date countdown reminders, and so on. With it, you will never miss those important days again, whether it's a loved one's birthday, a project completion day, or your son or daughter's graduation day.
The DATEDIF function is different from the functions we usually see. As we all know, generally we only need to enter the first few letters of a function in EXCEL, and EXCEL will automatically pop up the function. However, after all the letters of the function have been entered, EXCEL still does not have any prompts. Some friends may wonder whether there is such a function. In fact, the DATEDIF function is a hidden function in EXCEL. It is not available in the help and insertion formulas, and can only be entered manually.
There is a prompt for non-hidden function input
No prompt for hidden function input
The DATEDIF function can not only be used to calculate age, Length of service, seniority salary, project cycle, and can also be used as birthday countdown reminders, project completion date countdown reminders, etc. Let's get to know it below.
1. First introduction to DATEDIF
The DATEDIF function is used to calculate the difference between two dates and return the number of years, months and days between the two dates
Function structure: DATEDIF (start date, end date, return type)
1. Parameter explanation
1) Start date and end Date
Start date and end date are the two dates for which the difference needs to be calculated.
The input method of these two dates is as follows:
① You can directly enter the date with quotation marks, such as "2017/10/16". Note that the start date cannot be earlier than 1900, and the end date must be greater than the start date.
② You can also directly reference the date in the cell
③ You can also use other functions to get it, such as TODAY () (Note: The day of the example is February 15, 2019)
##2) Return type
The return type is used for Set the type of settlement result. The return type is text, and double quotes are required when entering. y: Returns the number of whole years between two dates (not counting if it is less than one year) m: Returns the number of whole months (if it is less than one month) d: Returns the number of days between two dates. ym: Calculate the difference in whole months between two dates after omitting the difference in whole years. For example, if the two dates (2017-4-20, 2019-2-20) differ by 1 year and October, and the whole year is omitted and the difference is 1 year, the result of ym is October. For another example, if the two dates (2018-4-20, 2019-2-20) are 10 months apart, the result of ym is October. yd: Calculate the difference in days between two dates after omitting the difference in whole years. For example, if the difference between two dates (2017-4-20, 2019-2-20) is 1 year and 306 days, and the whole year difference is omitted, the result of ym is 306 days. md: Calculate the difference in days between two dates after omitting the difference in whole years and whole months. For example, if the difference between two dates (2017-4-20, 2019-2-25) is 1 year, 10 months and 5 days, and the difference of 1 year and 10 months is omitted, the result of md is 5 days.2. Small chestnut
Give me a chestnutDATEDIF("2017/2/ 15","2019/2/15","y"), calculate the number of whole years difference between "2017/2/15" and "2019/2/15". The difference here is two complete years, so it equals 2.
, calculate the difference between two dates The number of months apart from a full year. The actual difference between the two dates is 25 months, including 2 whole years (24 months), so the ym type return value is 25-24=1. <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/024/aa1797dd147f6cfd77fe45e33627e0b4-10.png" class="lazy" style="max-width:90%" style="max-width:90%" alt="How to use DATEDIF() in Excel function learning" ></p>
<p><code>DATEDIF("2017/1/6","2019/2/15","yd")
, calculate the period between two dates excluding the whole year The number of days between. The actual difference between the two dates is 770 days, including 2 whole years (730 days), so the yd type return value is 770-730=40.
3. Use key points
1) Double quotes
to here, I believe that my friends already have a preliminary understanding of the DATEDIF function, and you can write a few formulas to practice. Please pay attention to the use of double quotation marks when writing formulas.
(1) If the 1st and 2nd parameters are to directly enter the date, the date must be in double quotes.
(2) The third parameter is text, so be sure to include double quotes.
2) Error type
If an error occurs in the DATEDIF function, there are usually three categories:
Error code |
Error reason |
NUM! |
①The input value of the return type of the third parameter of the function is incorrect ②The first parameter is larger than the second parameter |
#VALUE! |
The start or end date refers to a cell format that is not a date format |
#NAME? |
①The function input is incorrect ②The text type data does not have double quotes |
2. Practical application examples of DATEDIF function
1. Calculate age based on date of birth
Given the date of birth of the following employees, Find their age this year.
No peeking at the answer~
Formula: =DATEDIF(D2,TODAY() ,"y")
2. Calculate age based on ID number
The previous example already has the date of birth, so directly use the DATEDIF function to apply it The TODAY function can calculate age. If you only have an ID number, to calculate age, you need to extract the date of birth from the ID number and then calculate it. The formula is as follows:Formula analysis:
①Use the MID function to extract the 8-digit number of the date of birth in the ID card number.3. Calculate the employee’s length of service based on the date of joining (displayed in the form of year, month and day)
Use case 1 method of calculating age. If the time of employee joining is known, that is The employee's length of service in full years can be calculated. But if you need to calculate the detailed employee service length, such as how many years, months, and days, what should you do? The answer is as follows:4. Calculate seniority wages
According to the seniority wage regulations promulgated by the state in 2019, employees who have worked continuously for one year are 50 yuan/month; employees who have been working continuously for two years are 100 yuan/month. Yuan/month; 150 Yuan/month for three consecutive years; 180 Yuan/month for four consecutive years, and so on, with a cumulative cap of ten years. Are you confused? It’s okay, let’s go step by step, first calculate the length of service (calculated in full years). Formula:=DATEDIF(C2,D2,"y")
" is returned; if the seniority E2 is not less than 4, the seniority salary is 150 On the basis of increasing by 30 every year, the result of "" is returned.
5. Make employee birthday reminder
The following is an employee information table. We want to make a birthday reminder to remind an employee 7 days in advance that his birthday is coming.
Tips: Use it in combination with the IF function, think about it~
through
We usually calculate the number of days until the birthday by subtracting today's date from the upcoming birthday date. This formula is different from what we are used to. It calculates by subtracting the date of birth from today's date, and also reduces the date of birth by 7 days.
Why can this be done?
First, let’s take a look at the number of days between the current date and the date of birth under the yd return type. The following table takes the birth date of February 22, 1999 as an example, showing the number of days from yesterday, today, tomorrow, the day after tomorrow, etc. to the birth date.
N16 cell formula = DATEDIF($J$13,N15,"yd"), $J$13 represents the date of birth, and N15 represents a different current date. Obviously, the interval on the birthday is 0; if it is less than the birthday date, the closer the date is to the birthday, the larger the interval is, the closer it is to 365; if it is greater than the birthday date, the closer the date is to the birthday, the smaller the interval is. Approaching 0.
Secondly, in this case, directly apply the IF function to give a birthday reminder formula based on whether the interval is less than or equal to 7 =IF(DATEDIF($J$13,N15,"yd") Birthday is coming soon La","") cannot realize the reminder 7 days in advance. On the contrary, it can only realize the reminder on the birthday and 7 days after the birthday, as follows:
## Modification After judging the conditions, there will be no reminder on the birthday.
Ok, here, I believe everyone will understand the previous formula. On this basis, we can modify the formula to make the reminder more humane:
=IF(DATEDIF(D3-7,TODAY(),"yd")also"&7-DATEDIF(D3-7,TODAY(),"yd")&"It’s my birthday","")
A few more words: If we use the usual idea of subtracting the current date from the upcoming birthday date to calculate the number of days until the birthday, how should we write the birthday reminder formula? The answer is as follows:
=IF(DATEDIF(TODAY(),IF(TEXT(D3,"M月DD日")
月DD日"),YEAR(TODAY() 365),YEAR( TODAY()))&"year"&TEXT(D3,"M month DD day"),"yd")It's your birthday soon","")(today(),"m
This is a very long formula!!!
IF(TEXT(D3) in the formula ,"M month DD day")month DD day"),YEAR(TODAY() 365),YEAR(TODAY()))&"Year"&TEXT(D3,"M month DD day") is used to obtain Upcoming birthday date. Meaning: If the number of months and days in the date of birth is less than the number of months and days today, it means that this year’s birthday has passed, and the new birthday date should be YEAR(TODAY() 365)&"Year"&TEXT(D3,"M month DD day "; On the contrary, it means that this year's birthday has not passed yet, and the birthday date should be YEAR(TODAY())&"年"&TEXT(D3,"M month DD day".
YEAR(TODAY()) extracts this year's year and adds 365 to get next year's year.
TEXT(D3,"m month dd day") extracts the month and number in the date of birth.
At this point, the introduction of the DATEDIF function is complete. Whether it is calculating age, length of service, seniority wages, or giving birthday reminders, you can use DATEDIF. Of course, DATEDIF can also be used to calculate the project time, the number of days until completion, and provide a countdown reminder for completion. If you are doing personnel, payroll, or project management, then start practicing now!
Related learning recommendations: excel tutorial
The above is the detailed content of How to use DATEDIF() in Excel function learning. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Excel is often used to process data in daily office work, and it is often necessary to use the "filter" function. When we choose to perform "filtering" in Excel, we can only filter up to two conditions for the same column. So, do you know how to filter more than 3 keywords at the same time in Excel? Next, let me demonstrate it to you. The first method is to gradually add the conditions to the filter. If you want to filter out three qualifying details at the same time, you first need to filter out one of them step by step. At the beginning, you can first filter out employees with the surname "Wang" based on the conditions. Then click [OK], and then check [Add current selection to filter] in the filter results. The steps are as follows. Similarly, perform filtering separately again

If when opening a file that needs to be printed, we will find that the table frame line has disappeared for some reason in the print preview. When encountering such a situation, we must deal with it in time. If this also appears in your print file If you have questions like this, then join the editor to learn the following course: What should I do if the frame line disappears when printing a table in Excel? 1. Open a file that needs to be printed, as shown in the figure below. 2. Select all required content areas, as shown in the figure below. 3. Right-click the mouse and select the "Format Cells" option, as shown in the figure below. 4. Click the “Border” option at the top of the window, as shown in the figure below. 5. Select the thin solid line pattern in the line style on the left, as shown in the figure below. 6. Select "Outer Border"

In our daily work and study, we copy Excel files from others, open them to add content or re-edit them, and then save them. Sometimes a compatibility check dialog box will appear, which is very troublesome. I don’t know Excel software. , can it be changed to normal mode? So below, the editor will bring you detailed steps to solve this problem, let us learn together. Finally, be sure to remember to save it. 1. Open a worksheet and display an additional compatibility mode in the name of the worksheet, as shown in the figure. 2. In this worksheet, after modifying the content and saving it, the dialog box of the compatibility checker always pops up. It is very troublesome to see this page, as shown in the figure. 3. Click the Office button, click Save As, and then

eWe often use Excel to make some data tables and the like. Sometimes when entering parameter values, we need to superscript or subscript a certain number. For example, mathematical formulas are often used. So how do you type the subscript in Excel? ?Let’s take a look at the detailed steps: 1. Superscript method: 1. First, enter a3 (3 is superscript) in Excel. 2. Select the number "3", right-click and select "Format Cells". 3. Click "Superscript" and then "OK". 4. Look, the effect is like this. 2. Subscript method: 1. Similar to the superscript setting method, enter "ln310" (3 is the subscript) in the cell, select the number "3", right-click and select "Format Cells". 2. Check "Subscript" and click "OK"

When processing data, sometimes we encounter data that contains various symbols such as multiples, temperatures, etc. Do you know how to set superscripts in Excel? When we use Excel to process data, if we do not set superscripts, it will make it more troublesome to enter a lot of our data. Today, the editor will bring you the specific setting method of excel superscript. 1. First, let us open the Microsoft Office Excel document on the desktop and select the text that needs to be modified into superscript, as shown in the figure. 2. Then, right-click and select the "Format Cells" option in the menu that appears after clicking, as shown in the figure. 3. Next, in the “Format Cells” dialog box that pops up automatically

Most users use Excel to process table data. In fact, Excel also has a VBA program. Apart from experts, not many users have used this function. The iif function is often used when writing in VBA. It is actually the same as if The functions of the functions are similar. Let me introduce to you the usage of the iif function. There are iif functions in SQL statements and VBA code in Excel. The iif function is similar to the IF function in the excel worksheet. It performs true and false value judgment and returns different results based on the logically calculated true and false values. IF function usage is (condition, yes, no). IF statement and IIF function in VBA. The former IF statement is a control statement that can execute different statements according to conditions. The latter

In the study of software, we are accustomed to using excel, not only because it is convenient, but also because it can meet a variety of formats needed in actual work, and excel is very flexible to use, and there is a mode that is convenient for reading. Today I brought For everyone: where to set the excel reading mode. 1. Turn on the computer, then open the Excel application and find the target data. 2. There are two ways to set the reading mode in Excel. The first one: In Excel, there are a large number of convenient processing methods distributed in the Excel layout. In the lower right corner of Excel, there is a shortcut to set the reading mode. Find the pattern of the cross mark and click it to enter the reading mode. There is a small three-dimensional mark on the right side of the cross mark.

1. Open the PPT and turn the page to the page where you need to insert the excel icon. Click the Insert tab. 2. Click [Object]. 3. The following dialog box will pop up. 4. Click [Create from file] and click [Browse]. 5. Select the excel table to be inserted. 6. Click OK and the following page will pop up. 7. Check [Show as icon]. 8. Click OK.
