A simple Python package to calculate the number of days between two dates (inclusive).
- Calculate days between two dates, including both start and end dates
- Simple command-line interface
- Cross-platform support (Linux, macOS, Windows)
- No external dependencies - uses only Python standard library
- Clear output indicating inclusive calculation
- Support for dates from year 1 to 9999
pip install dayspanpip install git+https://github.com/YOUR_USERNAME/dayspan.gitgit clone https://github.com/YOUR_USERNAME/dayspan.git
cd dayspan
pip install .git clone https://github.com/YOUR_USERNAME/dayspan.git
cd dayspan
pip install -e .Basic usage:
dayspan 20250101 20251231Output:
365 days (from 2025-01-01 to 2025-12-31, inclusive)
Verbose output:
dayspan -v 20250101 20251231Output:
Start date: 2025-01-01
End date: 2025-12-31
Days from 2025-01-01 to 2025-12-31 (inclusive): 365 days
Help:
dayspan -hVersion:
dayspan --versionfrom dayspan import calculate_days
# Calculate days between two dates
days, start_formatted, end_formatted = calculate_days("20250101", "20251231")
print(f"{days} days from {start_formatted} to {end_formatted}")
# Output: 365 days from 2025-01-01 to 2025-12-31
# Parse individual dates
from dayspan import parse_date
date = parse_date("20250101")
print(date) # 2025-01-01 00:00:00dayspan 20250301 20250331
# Output: 31 days (from 2025-03-01 to 2025-03-31, inclusive)dayspan 20240101 20241231
# Output: 366 days (from 2024-01-01 to 2024-12-31, inclusive)dayspan 19930101 20241231
# Output: 11687 days (from 1993-01-01 to 2024-12-31, inclusive)dayspan 20250101 20250101
# Output: 1 days (from 2025-01-01 to 2025-01-01, inclusive)dayspan 20240201 20240229
# Output: 29 days (from 2024-02-01 to 2024-02-29, inclusive)DaySpan counts both the start and end dates, which is the intuitive way most people think about date ranges:
- From January 1 to January 31 = 31 days (the entire month)
- From Monday to Friday = 5 days (the work week)
- From today to today = 1 day (not 0)
This matches how we naturally count days on a calendar.
- Dates must be in
YYYYMMDDformat - Year: 0001-9999
- Month: 01-12
- Day: 01-31 (validated according to month and year)
The tool validates input dates and provides clear error messages:
# Invalid date format
dayspan 2025-01-01 2025-12-31
# Error: Invalid date format: '2025-01-01'. Expected YYYYMMDD format.
# End date before start date
dayspan 20251231 20250101
# Error: End date (20250101) must be after or equal to start date (20251231)
# Invalid date
dayspan 20250132 20251231
# Error: Invalid date: '20250132'. day is out of range for month- Python 3.9 or higher
- No external dependencies
# Option A
python test_dayspan.py
# Option B
pytest test_dayspan.py# Install build tools
pip install build
# Build distributions
python -m buildContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Cong Gao - [email protected]
- Thanks to all contributors who have helped with this project
- Inspired by the need for a simple, reliable day calculation tool
- should be connected with zenodo
- release
- v1.0.10d is not valid
- mkdir tests and mv the test into tests/
- exclude python 3.8 (the package does work for python 3.8 but the .toml does not work for python 3.8)
- include python version test
- keep github repo clean
- published automatically by github action
- update the python requirement
- version controled unified in .toml
- debug the version in command-line
- update the pip badge
- builded by .toml instead of setup.py
- Initial release
- Basic day calculation functionality
- Command-line interface
- Python API
- Cross-platform support
If you find this tool useful, please consider giving it a star on GitHub!