Need to find the ending boundary of a time period for date range queries or deadline calculations? This guide shows you how to use the End of Day API to get the exact end of any day, week, month, quarter, or year with proper timezone handling.
What is End of Day Calculation?
End of day (or end of period) calculation finds the ending boundary of a time period containing a given date. For example, the end of day for "2024-01-15 14:30:00" is "2024-01-15 23:59:59.999".
This is essential for creating inclusive date range queries, calculating deadlines, and ensuring accurate period boundaries across your application.
Supported Time Units
The API can find the end of the following periods:
- Second: End of the current second (999 milliseconds)
- Minute: End of the current minute (59.999 seconds)
- Hour: End of the current hour (59:59.999)
- Day: End of the current day (23:59:59.999)
- Week: End of the current week (configurable last day)
- Month: Last day of the current month at 23:59:59.999
- Quarter: Last day of the current quarter
- Year: December 31st at 23:59:59.999
Using the End of Day API
TinyFn provides a simple endpoint for end of period calculations:
GET https://api.tinyfn.io/v1/time/end-of
Headers: X-API-Key: your-api-key
{
"original": "2024-01-15T14:30:45.123Z",
"result": "2024-01-15T23:59:59.999Z",
"unit": "day",
"timezone": "UTC"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
date |
string | Date in ISO 8601 format (required) |
unit |
string | Unit: second, minute, hour, day, week, month, quarter, year (required) |
timezone |
string | IANA timezone (default: UTC) |
week_start |
string | First day of week: sunday or monday (default: sunday) |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/time/end-of?' + new URLSearchParams({
date: '2024-02-15T14:30:00Z',
unit: 'month'
}),
{ headers: { 'X-API-Key': 'your-api-key' } }
);
const result = await response.json();
console.log(result.result); // 2024-02-29T23:59:59.999Z (leap year!)
Python
import requests
response = requests.get(
'https://api.tinyfn.io/v1/time/end-of',
params={
'date': '2024-05-15T10:00:00Z',
'unit': 'quarter'
},
headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
print(result['result']) # 2024-06-30T23:59:59.999Z (Q2 ends June 30)
cURL
curl "https://api.tinyfn.io/v1/time/end-of?date=2024-01-15&unit=year" \
-H "X-API-Key: your-api-key"
Common Use Cases
- Date Range Queries: Get inclusive end boundaries for database queries
- Deadline Calculation: Find end of business day, month, or quarter
- Report Generation: Define report end boundaries
- Subscription Expiry: Calculate when subscriptions end
- Trial Periods: Determine trial end dates
Best Practices
- Use with start-of: Combine with start-of-day API for complete date ranges
- Specify timezone: End of day varies by timezone
- Handle precision: Consider whether you need millisecond precision (23:59:59.999) or second precision (23:59:59)
- Inclusive vs exclusive: Decide if your queries should include or exclude the boundary
Try the End of Day API
Get your free API key and simplify your date boundary calculations.
Get Free API Key