Need to calculate business days between dates or add working days to a date? This guide covers everything about business day calculation via API, including handling weekends, holidays, and implementation examples in multiple programming languages.
What are Business Days?
Business days (or working days) are days when businesses typically operate - usually Monday through Friday, excluding public holidays. Different countries and industries may have different definitions.
Example: From Monday Jan 1 to Friday Jan 12 = 9 business days (excluding 2 weekends)
Calculation Complexity
Factors that make business day calculation complex:
Weekends
Most countries use Saturday-Sunday weekends, but some use Friday-Saturday.
Public Holidays
Holidays vary by country, region, and even company.
Regional Differences
Different countries have different working weeks and holiday schedules.
Using the Business Days API
TinyFn provides a flexible endpoint to calculate business days:
GET https://api.tinyfn.io/v1/time/business-days?start=2024-01-01&end=2024-01-15
Headers: X-API-Key: your-api-key
{
"start_date": "2024-01-01",
"end_date": "2024-01-15",
"business_days": 10,
"total_days": 14,
"weekends": 4,
"holidays_excluded": 0,
"weekend_days": ["saturday", "sunday"]
}
Parameters
| Parameter | Type | Description |
|---|---|---|
start |
string | Start date in YYYY-MM-DD format (required) |
end |
string | End date in YYYY-MM-DD format (required) |
country |
string | Country code for holidays (optional, e.g., US, UK) |
holidays |
array | Custom holiday dates to exclude (optional) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/time/business-days?start=2024-01-01&end=2024-01-31&country=US',
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const result = await response.json();
console.log(`Business days: ${result.business_days}`);
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/time/business-days',
params={'start': '2024-01-01', 'end': '2024-01-31', 'country': 'US'},
headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(f"Business days: {result['business_days']}")
cURL
curl "https://api.tinyfn.io/v1/time/business-days?start=2024-01-01&end=2024-01-31&country=US" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Shipping Estimates: Calculate delivery dates based on business days
- SLA Tracking: Measure response times in business days
- Project Planning: Estimate project durations accurately
- Payment Terms: Calculate due dates (e.g., Net 30 business days)
- HR Systems: Track working days for payroll and PTO
Best Practices
- Know your audience: Use appropriate country/region for holidays
- Document assumptions: Clarify what counts as a business day
- Handle edge cases: Consider what happens when start/end are weekends
- Update holidays: Keep holiday lists current for accurate results
Try the Business Days Calculator API
Get your free API key and start calculating business days in seconds.
Get Free API Key