FTJ
← Blog
Everyday

How to Calculate Days Between Dates — For Planning, Scheduling & Deadlines

Learn how to calculate the number of days between two dates for project planning, deadline tracking, and scheduling. Includes methods, formulas, and free tools.

Why Calculate Days Between Dates?

Calculating the number of days between two dates is a common task across many scenarios:

  1. Project management: Track how many days a project has been running
  2. Deadline tracking: Count down days remaining until a deadline
  3. Age calculation: Calculate a person's age in days
  4. Event planning: Count days until a wedding, vacation, or conference
  5. Subscription tracking: Calculate days left in a free trial
  6. Work anniversary: Calculate years/months/days of employment
  7. Rental periods: Calculate lease or rental durations
  8. Travel planning: Calculate trip duration

Understanding Date Differences

When calculating days between dates, there are two common approaches:

1. Inclusive Counting

Counts the start date and end date as part of the duration.

Example: Jan 1 to Jan 3 = 3 days (Jan 1, Jan 2, Jan 3)

2. Exclusive Counting

Counts only the full days between the start and end dates.

Example: Jan 1 to Jan 3 = 2 days (the period from end of Jan 1 to start of Jan 3)

Most date calculators use exclusive counting (end date - start date), but some contexts (like hotel stays) use inclusive counting.

Method 1: Using FreeToolJet's Date Difference Calculator

Our Date Difference Calculator provides instant, accurate results:

Step-by-Step Guide

  1. Open the Date Difference Calculator tool
  2. Select or type the start date
  3. Select or type the end date
  4. Choose the counting method (inclusive or exclusive)
  5. View the results:

Features

  • Multiple formats: See results in days, weeks, months, and years
  • Business days option: Exclude weekends from the count
  • Workday calculator: Exclude weekends and holidays
  • Reverse calculation: Calculate what date is X days from a start date
  • Historical dates: Works with any date from 0001-01-01 onward

Method 2: Manual Calculation

Using a Calendar

For rough estimates:

  1. Count the number of full months between dates
  2. Multiply by 30 (or 31, or use actual month lengths)
  3. Add/subtract remaining days

Example: March 15 to July 20 - March 15 → March 31 = 16 days - April = 30 days - May = 31 days - June = 30 days - July 1 → July 20 = 20 days - Total = 16 + 30 + 31 + 30 + 20 = 127 days

Using the "30-Day Month" Approximation

For quick estimates: ` Days = (Years × 365) + (Months × 30) + Days `

Example: 2 years, 3 months, 15 days ` (2 × 365) + (3 × 30) + 15 = 730 + 90 + 15 = 835 days `

⚠️ This is approximate. Use a proper calculator for exact results.

Method 3: Programming Languages

Python

# Method 1: Using datetime date1 = datetime(2024, 1, 15) date2 = datetime(2024, 7, 20) difference = date2 - date1 print(f"Days between: {difference.days}") # Output: Days between: 187

# Method 2: Using date (for dates without time) date1 = date(2024, 1, 15) date2 = date(2024, 7, 20) difference = date2 - date1 print(f"Days between: {difference.days}")

# Method 3: Absolute difference (always positive) from datetime import datetime date1 = datetime(2024, 7, 20) date2 = datetime(2024, 1, 15) difference = abs((date2 - date1).days) print(f"Absolute days: {difference}")

# Method 4: Exclude weekends (business days) import numpy as np def business_days(start, end): return np.busday_count(start, end)

print(business_days(date(2024, 1, 15), date(2024, 7, 20))) `

JavaScript/Node.js

// Method 1: Using Date objects
const date1 = new Date('2024-01-15');
const date2 = new Date('2024-07-20');
const differenceMs = date2 - date1;
const differenceDays = Math.floor(differenceMs / (1000 * 60 * 60 * 24));
console.log(`Days between: ${differenceDays}`);

// Method 2: Handle time zones properly function daysBetween(startDate, endDate) { const start = new Date(startDate); start.setHours(0, 0, 0, 0); const end = new Date(endDate); end.setHours(0, 0, 0, 0); return Math.floor((end - start) / (1000 * 60 * 60 * 24)); }

console.log(daysBetween('2024-01-15', '2024-07-20'));

// Method 3: Using date-fns library (recommended for production) // npm install date-fns const { differenceInDays, differenceInBusinessDays } = require('date-fns');

const days = differenceInDays(new Date('2024-07-20'), new Date('2024-01-15')); console.log(days);

const businessDays = differenceInBusinessDays(new Date('2024-07-20'), new Date('2024-01-15')); console.log(businessDays); `

SQL

-- MySQL / MariaDB
SELECT DATEDIFF('2024-07-20', '2024-01-15') AS days_between;

-- PostgreSQL SELECT '2024-07-20'::date - '2024-01-15'::date AS days_between; -- Output: 187

-- SQL Server SELECT DATEDIFF(day, '2024-01-15', '2024-07-20') AS days_between; -- Output: 187

-- Oracle SELECT TO_DATE('2024-07-20', 'YYYY-MM-DD') - TO_DATE('2024-01-15', 'YYYY-MM-DD') AS days_between FROM dual; -- Output: 187 `

Excel / Google Sheets

=B2-A2

Where A2 is the start date and B2 is the end date.

For business days (excluding weekends): ` =NETWORKDAYS(A2, B2) `

For business days excluding holidays: ` =NETWORKDAYS(A2, B2, C2:C10) `

Where C2:C10 contains holiday dates.

Handling Special Cases

Leap Years

Leap years (with 366 days) occur: - Every year divisible by 4 - Except years divisible by 100 - Unless also divisible by 400

Examples: - 2000: Leap year (divisible by 400) - 1900: Not a leap year (divisible by 100 but not 400) - 2024: Leap year (divisible by 4, not by 100)

When calculating days between dates that span leap years, account for the extra day (February 29).

Time Zones

When dates include times, time zones matter:

from datetime import datetime

# Naive datetime (no time zone) date1 = datetime(2024, 1, 15, 23, 0, 0) # 11:00 PM date2 = datetime(2024, 1, 16, 1, 0, 0) # 1:00 AM next day print((date2 - date1).days) # Output: 0 (less than 24 hours)

# Aware datetime (with time zone) eastern = pytz.timezone('US/Eastern') date1 = eastern.localize(datetime(2024, 1, 15, 23, 0, 0)) date2 = eastern.localize(datetime(2024, 1, 16, 1, 0, 0)) print((date2 - date1).days) # Still 0 `

Best practice: When calculating date differences, set times to noon (12:00:00) to avoid daylight saving time issues, or use date-only objects.

Different Calendar Systems

The Gregorian calendar (used internationally) has: - 365 days in a common year - 366 days in a leap year - Months of varying lengths (28-31 days)

Other calendar systems: - Julian calendar: 365.25 days/year (13-day difference from Gregorian) - Islamic (Hijri) calendar: 354-355 days/year - Hebrew calendar: 353-385 days/year

When working with historical dates, verify which calendar system was in use.

Business Days Calculation

To calculate working days (excluding weekends and holidays):

Python

def business_days(start_date, end_date, holidays=[]): current_date = start_date business_days = 0 while current_date <= end_date: # Monday = 0, Sunday = 6 if current_date.weekday() < 5 and current_date not in holidays: business_days += 1 current_date += timedelta(days=1) return business_days

start = datetime(2024, 1, 15) end = datetime(2024, 1, 31) holidays = [datetime(2024, 1, 15)] # Martin Luther King Day print(business_days(start, end, holidays)) `

JavaScript

function businessDays(startDate, endDate, holidays = []) {
    let currentDate = new Date(startDate);
    let days = 0;
    
    while (currentDate <= endDate) {
        const dayOfWeek = currentDate.getDay();
        const isWeekend = dayOfWeek === 0 || dayOfWeek === 6;
        const isHoliday = holidays.some(h => 
            h.toDateString() === currentDate.toDateString()
        );
        
        if (!isWeekend && !isHoliday) {
            days++;
        }
        
        currentDate.setDate(currentDate.getDate() + 1);
    }
    
    return days;

const start = new Date('2024-01-15'); const end = new Date('2024-01-31'); const holidays = [new Date('2024-01-15')]; // MLK Day console.log(businessDays(start, end, holidays)); `

Common Date Difference Formulas

CalculationFormula
Days between two datesend - start (in days)
Age in daystoday - birthdate
Project durationend_date - start_date + 1 (inclusive)
Days remainingdeadline - today
Days elapsedtoday - start_date
Add N days to datedate + N days
Subtract N days from datedate - N days

Date Formats

Different regions use different date formats:

FormatExampleRegion
YYYY-MM-DD2024-01-15ISO 8601 (international standard)
MM/DD/YYYY01/15/2024United States
DD/MM/YYYY15/01/2024Europe, most of the world
DD.MM.YYYY15.01.2024Germany, Russia

Always use ISO 8601 (YYYY-MM-DD) for data storage and APIs to avoid ambiguity.

Tips for Accurate Date Calculations

  1. Be consistent with time zones: Convert all dates to UTC before calculating
  2. Watch out for daylight saving time: Use noon times or date-only objects
  3. Account for leap years: Use built-in date libraries, don't calculate manually
  4. Clarify inclusive vs. exclusive: Specify whether you're counting the start/end dates
  5. Test edge cases: Test with dates spanning month boundaries, year boundaries, and leap years
  6. Use ISO 8601 format: Avoid MM/DD vs DD/MM confusion

Related Tools

Try These Tools

More Articles