Skip to main content

A simple tool to count days between two dates (YYYYMMDD).

Project description

DaySpan

PyPI Python Support License: MIT

A simple Python package to calculate the number of days between two dates (inclusive).

Features

  • 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

Installation

From PyPI

pip install dayspan

From GitHub

pip install git+https://github.com/YOUR_USERNAME/dayspan.git

From source

git clone https://github.com/YOUR_USERNAME/dayspan.git
cd dayspan
pip install .

For development

git clone https://github.com/YOUR_USERNAME/dayspan.git
cd dayspan
pip install -e .

Usage

Command Line Interface

Basic usage:

dayspan 20250101 20251231

Output:

365 days (from 2025-01-01 to 2025-12-31, inclusive)

Verbose output:

dayspan -v 20250101 20251231

Output:

Start date: 2025-01-01
End date: 2025-12-31
Days from 2025-01-01 to 2025-12-31 (inclusive): 365 days

Help:

dayspan -h

Version:

dayspan --version

Python API

from 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:00

Examples

Days in a month

dayspan 20250301 20250331
# Output: 31 days (from 2025-03-01 to 2025-03-31, inclusive)

Days in a leap year

dayspan 20240101 20241231
# Output: 366 days (from 2024-01-01 to 2024-12-31, inclusive)

Days between two specific dates

dayspan 19930101 20241231
# Output: 11687 days (from 1993-01-01 to 2024-12-31, inclusive)

Single day

dayspan 20250101 20250101
# Output: 1 days (from 2025-01-01 to 2025-01-01, inclusive)

Leap year February

dayspan 20240201 20240229
# Output: 29 days (from 2024-02-01 to 2024-02-29, inclusive)

Why 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.

Input Format

  • Dates must be in YYYYMMDD format
  • Year: 0001-9999
  • Month: 01-12
  • Day: 01-31 (validated according to month and year)

Error Handling

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

Requirements

  • Python 3.9 or higher
  • No external dependencies

Development

Running Tests

# Option A
python test_dayspan.py

# Option B
pytest test_dayspan.py

Building from Source

# Install build tools
pip install build

# Build distributions
python -m build

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Cong Gao - cnggao@gmail.com

Acknowledgments

  • Thanks to all contributors who have helped with this project
  • Inspired by the need for a simple, reliable day calculation tool

Changelog

v1.0.10a1 (2025-08-15)

  • v1.0.10d is not valid

v1.0.10d (2025-08-15)

  • mkdir tests and mv the test into tests/

v1.0.10c (2025-08-15)

  • exclude python 3.8 (the package does work for python 3.8 but the .toml does not work for python 3.8)

v1.0.10b (2025-08-15)

  • include python version test

v1.0.10a (2025-08-15)

  • keep github repo clean

v1.0.9 (2025-08-15)

  • published automatically by github action

v1.0.8 (2025-08-13)

  • update the python requirement

v1.0.7 (2025-08-13)

  • version controled unified in .toml

v1.0.6 (2025-08-13)

  • debug the version in command-line

v1.0.5 (2025-08-12)

  • update the pip badge

v1.0.4 (2025-08-12)

  • builded by .toml instead of setup.py

v1.0.3 (2025-07-03)

  • 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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dayspan-1.0.10a1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dayspan-1.0.10a1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file dayspan-1.0.10a1.tar.gz.

File metadata

  • Download URL: dayspan-1.0.10a1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for dayspan-1.0.10a1.tar.gz
Algorithm Hash digest
SHA256 cdaa6d65436bbbfbb30cb5089caef99caf98f98a1668fa97d87aa460a343d39b
MD5 f91fc213e931c6f0cfb902b22e00a211
BLAKE2b-256 09f7353ad775a9df7470133d170d8d5b77e887456865d5c0da74e554937e532f

See more details on using hashes here.

File details

Details for the file dayspan-1.0.10a1-py3-none-any.whl.

File metadata

  • Download URL: dayspan-1.0.10a1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.6

File hashes

Hashes for dayspan-1.0.10a1-py3-none-any.whl
Algorithm Hash digest
SHA256 d5de85b01f37f455a1e7297eadcdaf0c5213ff03a63706a4eec803a23367f0a9
MD5 f3022bd22ec82d1b48d3074ac20731af
BLAKE2b-256 f525e2f860afce9be6ce5aa968dc1d2790be725ee04bc5137e2c741d1468cda5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page