Vous êtes sur la page 1sur 6

DATEDIF function

Calculates the number of days, months, or years between two dates. Warning: Excel provides the
DATEDIF function in order to support older workbooks from Lotus 1-2-3. The DATEDIF function may
calculate incorrect results under certain scenarios. Please see the known issues section of this article for
further details.



Start_date A date that represents the first, or starting, date of the period. Dates may be entered as
text strings within quotation marks (for example, "2001/1/30"), as serial numbers (for example, 36921,
which represents January 30, 2001, if you're using the 1900 date system), or as the results of other
formulas or functions (for example, DATEVALUE("2001/1/30")).

End_date A date that represents the last, or ending, date of the period.

Note: If the Start_date is greater than the End_date, the result will be #NUM!.

Unit The type of information that you want returned:

Unit Returns
"Y" The number of complete years in the period.
"M" The number of complete months in the period.
"D" The number of days in the period.
"MD" The difference between the days in start_date and end_date. The months and years of the dates are ignored.

Important: We don't recommend using the "MD" argument, as there are known limitations with it. See the know
issues section below.
"YM" The difference between the months in start_date and end_date. The days and years of the dates are ignored
"YD" The difference between the days of start_date and end_date. The years of the dates are ignored.


 Dates are stored as sequential serial numbers so they can be used in calculations. By default, December
31, 1899 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,448 days after
January 1, 1900.
 The DATEDIF function is useful in formulas where you need to calculate an age.


Start_date End_date Formula Description (Result)

1/1/2001 1/1/2003 =DATEDIF(Start_date,End_date,"Y") Two complete years in the period
6/1/2001 8/15/2002 =DATEDIF(Start_date,End_date,"D") 440 days between June 1, 2001,
and August 15, 2002 (440)
6/1/2001 8/15/2002 =DATEDIF(Start_date,End_date,"YD") 75 days between June 1 and August
15, ignoring the years of the dates

Known issues

The "MD" argument may result in a negative number, a zero, or an inaccurate result. If you are trying to
calculate the remaining days after the last completed month, here is a workaround:

This formula subtracts the first day of the ending month (5/1/2016) from the original end date in cell
E17 (5/6/2016). Here's how it does this: First the DATE function creates the date, 5/1/2016. It creates it
using the year in cell E17, and the month in cell E17. Then the 1 represents the first day of that month.
The result for the DATE function is 5/1/2016. Then, we subtract that from the original end date in cell
E17, which is 5/6/2016. 5/6/2016 minus 5/1/2016 is 5 days.
TEXT function

Excel for Office 365 Excel for Office 365 for Mac Excel 2019 Excel 2016 More...

The TEXT function lets you change the way a number appears by applying formatting to it with format
codes. It's useful in situations where you want to display numbers in a more readable format, or you
want to combine numbers with text or symbols.

Note: The TEXT function will convert numbers to text, which may make it difficult to reference in later
calculations. It’s best to keep your original value in one cell, then use the TEXT function in another cell.
Then, if you need to build other formulas, always reference the original value and not the TEXT function

Technical Details


In its simplest form, the TEXT function says:

 =TEXT(Value you want to format, "Format code you want to apply")

Here are some popular examples, which you can copy directly into Excel to experiment with on your
own. Notice the format codes within quotation marks.

Formula Description
=TEXT(1234.567,"$#,##0.00") Currency with a thousands separator and 2 decimals, like $1,234.57.
Note that Excel rounds the value to 2 decimal places.
=TEXT(TODAY(),"MM/DD/YY") Today’s date in MM/DD/YY format, like 03/14/12
=TEXT(TODAY(),"DDDD") Today’s day of the week, like Monday
=TEXT(NOW(),"H:MM AM/PM") Current time, like 1:29 PM
=TEXT(0.285,"0.0%") Percentage, like 28.5%
=TEXT(4.34 ,"# ?/?") Fraction, like 4 1/3
=TRIM(TEXT(0.34,"# ?/?")) Fraction, like 1/3. Note this uses the TRIM function to remove the
leading space with a decimal value.
=TEXT(12200000,"0.00E+00") Scientific notation, like 1.22E+07
=TEXT(1234567898,"[<=9999999]###-####;(###) Special (Phone number), like (123) 456-7898
Formula Description
=TEXT(1234,"0000000") Add leading zeros (0), like 0001234
=TEXT(123456,"##0° 00' 00''") Custom - Latitude/Longitude

Note: Although you can use the TEXT function to change formatting, it’s not the only way. You can
change the format without a formula by pressing CTRL+1 (or +1 on the Mac), then pick the format you
want from the Format Cells > Number dialog.

Download our examples

You can download an example workbook with all of the TEXT function examples you'll find in this article,
plus some extras. You can follow along, or create your own TEXT function format codes.

Download Excel TEXT function examples

Other format codes that are available

You can use the Format Cells dialog to find the other available format codes:

1. Press Ctrl+1 ( +1 on the Mac) to bring up the Format Cells dialog.

2. Select the format you want from the Number tab.
3. Select the Custom option,
4. The format code you want is now shown in the Type box. In this case, select everything from
the Typebox except the semicolon (;) and @ symbol. In the example below, we selected and copied just
5. Press Ctrl+C to copy the format code, then press Cancel to dismiss the Format Cells dialog.
6. Now, all you need to do is press Ctrl+V to paste the format code into your TEXT formula, like:
=TEXT(B2,"mm/dd/yy"). Make sure that you paste the format code within quotes ("format code"),
otherwise Excel will throw an error message.
Format codes by category

Following are some examples of how you can apply different number formats to your values by using
the Format Cells dialog, then use the Custom option to copy those format codes to your TEXT function.

Common scenario

The TEXT function is rarely used by itself, and is most often used in conjunction with something else.
Let’s say you want to combine text and a number value, like “Report Printed on: 03/14/12”, or “Weekly
Revenue: $66,348.72”. You could type that into Excel manually, but that defeats the purpose of having
Excel do it for you. Unfortunately, when you combine text and formatted numbers, like dates, times,
currency, etc., Excel doesn’t know how you want to display them, so it drops the number formatting.
This is where the TEXTfunction is invaluable, because it allows you to force Excel to format the values
the way you want by using a format code, like "MM/DD/YY" for date format.

In the following example, you’ll see what happens if you try to join text and a number without using
the TEXT function. In this case, we’re using the ampersand (&) to concatenate a text string, a space (" "),
and a value with =A2&" "&B2.
As you can see, Excel removed the formatting from the date in cell B2. In the next example, you'll see
how the TEXT function lets you apply the format you want.

Our updated formula is:

 Cell C2:=A2&" "&TEXT(B2,"mm/dd/yy") - Date format