📖 Guide

Working with Dates: Days, Workdays and the Calendar's Quirks

Why '30 days' and '30 business days' differ by 12, leap-year rules, and the Gregorian-Julian transition that ate 10 days in 1582.

Ad Slot. Top Banner

The Deadline That Moved Without Anyone Noticing

A contractor receives a purchase order with payment due "30 days from invoice." The invoice date is January 30. Thirty calendar days later is March 1 in a non-leap year, or February 29 in a leap year. "30 days" sounds unambiguous until the month has 31 days, or 28 days, or a month boundary falls awkwardly. Add the phrase "30 business days" and the deadline shifts by roughly 12 additional days, landing somewhere around mid-April. The difference between these two interpretations can determine whether a contractor gets paid, whether a warranty claim is valid, or whether a legal filing is timely.

Date arithmetic sits at the center of contracts, project management, medical records, financial settlements, and software systems. Computers store dates as integers (the number of days since a reference point), which makes subtraction and addition exact. Humans use months, which have different lengths, creating ambiguities that require explicit rules to resolve.

This guide covers how computers count days using the Unix epoch, the Gregorian calendar rules for leap years, ISO 8601 date formatting, how to count business days vs calendar days, and the "30-day month" problem that causes contract disputes.

How Computers Count Days: The Unix Epoch

Every major computing platform stores dates as a number. The most common reference point is the Unix epoch: midnight, January 1, 1970, Coordinated Universal Time (UTC). A Unix timestamp counts the number of seconds elapsed since that moment. May 21, 2026 at midnight UTC equals Unix timestamp 1,779,148,800.

Date arithmetic in software works by subtracting timestamps and converting seconds to days (divide by 86,400). "Days between January 15 and March 20" becomes (Unix timestamp of March 20) minus (Unix timestamp of January 15), divided by 86,400. The result is exact, assuming both dates use the same timezone.

ISO 8601 is the international standard format for writing dates: YYYY-MM-DD. January 15, 2026 appears as 2026-01-15. The format sorts lexicographically in the correct chronological order, which makes it the preferred format for databases, file names, and any system where dates get compared as text strings. The US format (MM/DD/YYYY) and European format (DD/MM/YYYY) both create ambiguity: 01/02/2026 means January 2 in the US and February 1 in Europe.

ISO 8601 also defines week numbers: week 1 is the week containing the first Thursday of the year. January 1 sometimes falls in week 52 or 53 of the prior year (if January 1 is a Friday, Saturday, or Sunday), a fact that surprises developers who assume "week 1 starts January 1."

Gregorian Calendar Rules and Leap Year Math

The Gregorian calendar introduced in October 1582 corrected the Julian calendar's slight over-counting of leap years. The rule:

  • A year is a leap year if divisible by 4.
  • Exception: years divisible by 100 are not leap years.
  • Exception to the exception: years divisible by 400 are leap years.

Results: 1900 was not a leap year (divisible by 100 but not 400). 2000 was a leap year (divisible by 400). 2100 will not be a leap year. The average year in the Gregorian calendar is exactly 365.2425 days, close enough to the actual solar year (365.24219 days) that the calendar drifts only one day every 3,300 years.

Code to test for a leap year: year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)

The months and their day counts: January 31, February 28/29, March 31, April 30, May 31, June 30, July 31, August 31, September 30, October 31, November 30, December 31. The mnemonic for the 30-day months: April, June, September, November. All others have 31, except February.

Days between two dates: the most reliable manual method counts forward from the earlier date. From January 30 to March 1: January has 31 days, so January 30 to January 31 = 1 day. February (non-leap year) has 28 days: add 28. March 1 = add 1. Total: 30 days. The end date lands on March 1.

Ad Slot — In-Content

Common Misconceptions

  • Myth: "One month" from January 31 is February 28. Calendar arithmetic for months does not work by adding a fixed number of days. "One month from January 31" runs into a non-existent date: February 31. Software and contracts resolve this differently. Most software rolls to the last day of the target month: February 28 (or 29 in a leap year). Some contracts specify "last business day of the month" instead. "Add one month" is ambiguous for any date above the 28th.