Calculating the number of days between two dates is a common task in Google Sheets, essential for understanding time intervals in projects, events, or personal agendas. While Google Sheets doesn't have a built-in formula for this, we can achieve this using simple arithmetic and the DATEDIF function.

The DATEDIF function in Google Sheets calculates the difference between two dates based on a specified unit. However, DATEDIF is not as straightforward as one might hope when it comes to finding the number of days. Still, with a little creativity, we can indeed calculate the number of days between two dates.

Understanding the DATEDIF Function in Google Sheets
Before we dive into calculating the difference in days, it's crucial to understand the DATEDIF function's syntax and units of measurement.

DATEDIF(start_date, end_date, unit) where:
- start_date: The starting date (e.g., "2022-12-31").
- end_date: The ending date (e.g., "2023-01-15").
- unit: The unit of measurement. DATEDIF supports "D" for days, "M" for months, and "Y" for years. For our use-case, we're interested in "D".

Limitation of DATEDIF with Days
When using "D" as the unit in DATEDIF, it doesn't return the exact number of days. Instead, it provides the number of whole days, ignoring the fraction. For example:
| DATEDIF("2022-12-31", "2023-01-01", "D") | = 0 |
| DATEDIF("2022-12-31", "2023-01-02", "D") | = 1 |

As you can see, DATEDIF doesn't account for the partial day on January 1, 2023.
Adjusting the DATEDIF Formula for Days
To accurately calculate the number of days, we need to modify the DATEDIF formula. The trick is to use the EDATE function, which adjusts the start date by the specified number of months.

Here's the formula to calculate the number of days between two dates in Google Sheets:
=EDATE(end_date, start_date) - start_date + 1






Let's break this down:
EDATE(end_date, start_DATE + 1): Adjusts the end_date by one month from the start date.end_date: Returns the original end_date.start_date: Subtracts the start_date from the adjusted end_date and adds 1 to account for the missing day.
Alternative Formula using the NETWORKDAYS Function
Another approach to calculate the number of days between two dates involves the NETWORKDAYS function. NETWORKDAYS counts the number of whole workdays between two dates, excluding weekends. However, it doesn't include the starting date, so we need to adjust it accordingly.
Here's the formula to calculate the number of total days using NETWORKDAYS:
=NETWORKDAYS(start_date, end_date) + 1
Adjusting for Holidays using the NETWORKDAYS Function
If you need to account for holidays as well, you can use the NETWORKDAYS.INTL function, which allows you to specify both the weekend days and holidays.
The formula would look like this: =NETWORKDAYS.INTL(start_date, end_date, [weekend_days], [holidays]) where:
[weekend_days]: An array of numbers representing the weekend days (e.g., {7, 14} for Saturday and Sunday).[holidays]: A range of cells containing the holiday dates.
Remember to adjust the formulas to match your specific range and dates.
Using the ARRAYFORMULA Function
If you want to calculate the number of days between two dates for multiple cells or a range of cells, use the ARRAYFORMULA function to apply the formula to each cell in the range.
The formula would look like this: =ARRAYFORMULA(EDATE(end_date_range, start_date_range) - start_date_range + 1)
No matter your approach, calculating the number of days between two dates in Google Sheets requires a combination of functions and a touch of creativity. With these formulas, you can effectively determine time intervals for any purpose.
Now that you've mastered calculating the difference in days, explore other Google Sheets functions to enhance your productivity and analytics capabilities. Happy calculating!