Applies ToMaci jaoks ette nähtud Microsoft 365 rakendus Excel Excel 2024 Excel 2024 for Mac Excel 2021 for Mac

You can quickly find the difference between two dates, control the format of the result, and extend the calculation to a list of dates. For example, you can quickly subtract one date from another date, or calculate the duration of items on a project schedule.

Use the provided sample data and the following procedures to learn how to calculate dates in a project schedule.

Copy the sample data

  1. Copy the following sample data to cell A1 on a blank sheet.

    Task

    Start date

    End date

    Duration

    Create Project Plan

    6/8/2011

    9/20/11

    Phase 1

    9/21/11

    6/2/2012

    Phase 2

    6/3/2012

    12/10/2014

    Phase 3

    12/11/2014

    4/20/2017

  2. Press The Command button on macOS.+ C .

  3. In the sheet, select cell A1, and then press The Command button on macOS.+ V .

Calculate the difference in days

Calculate the number of days between two dates

  1. Select cell D2, which is the first blank cell in the Duration column.

  2. Type =C2-B2, and then press RETURN .

    Excel displays the result as the number of days between the two dates (104).

  3. Select cell D2.

  4. To copy the formula into the remaining rows, drag the fill handle   Fill handle.

    Excel adjusts the cell references automatically to include the correct values for each row.

Calculate the number of workdays between two dates

  1. Select cell D2, which is the first blank cell in the Duration column.

    If the cell is not blank, on the Edit menu, point to Clear, and then click All.

  2. On the Formulas tab, click Insert Function.

    • Insert Function option on the ribbon
  3. In the Formula Builder search box, type NETWORKDAYS.

  4. In the list that appears, double-click NETWORKDAYS.

  5. Under Arguments, click the box next to start_date, and then on the sheet, select cell B2 (6/8/2011)

  6. Under Arguments, click the box next to end_date, and then on the sheet, select cell C2 (9/20/2011)

  7. Leave the box next to holidays blank.

  8. Press RETURN .

    The result is 75 working days, not accounting for holidays.

  9. Select cell D2.

  10. To copy the formula into the remaining rows, drag the fill handle   Fill handle.

    Excel adjusts the cell references automatically to include the correct values for each row.

    Tip: See NETWORKDAYS function and NETWORKDAYS.INTL function to learn more about these formulas, including how to account for holidays.

Calculate the number of months between two dates in the same year

Excel treats months as values (1 through 12), which makes it easy to subtract an earlier date from another date as long as both dates fall in the same year. Use the MONTH function to obtain the month value for each date, and then calculate the difference between the values.

  1. Select cell D2, which is the first blank cell in the Duration column.

    If the cell is not blank, on the Edit menu, point to Clear, and then click All.

  2. In cell D2, type =MONTH(C2)-MONTH(B2), and then press RETURN .

    The result is 3.

Calculate the number of months between two dates in different years

When you have to find the number of months between dates that fall in different years, you can use a formula that determines the number of years between the two dates, converts the difference in years to months, and then accounts for any additional months to obtain an accurate result. Use the MONTH and YEAR functions to make this calculation.

  1. Select cell D3.

    If the cell is not blank, on the Edit menu, point to Clear, and then click All.

  2. In cell D3, type =(YEAR(C3)-YEAR(B3))*12+MONTH(C3)-MONTH(B3), and then press RETURN .

    The result is 9.

Calculate the number of years between two dates

Excel treats years as values. Use the YEAR function to obtain the year value for each date, and then calculate the difference between the values.

  1. Select cell D4.

    If the cell is not blank, on the Edit menu, point to Clear, and then click All.

  2. In cell D4, type =YEAR(C4)-YEAR(B4) and then press RETURN .

    The result is 2.

See Also

Subtract times

Show dates as days of the week

Insert and format the current date and time

Kas vajate veel abi?

Kas soovite rohkem valikuvariante?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.