Random Date Generator
Generate a random date within a specified range
2015-10-03About This Tool
Picks a uniformly random date within a user-specified range. Internally, the start and end dates are converted to Unix timestamps; a random integer between them is generated and converted back to a calendar date.
Supports inclusive endpoints, optional time-of-day randomization, and weekday filtering (e.g., business days only).
The internal mechanism is straightforward: convert start and end dates to integer milliseconds since epoch (1970-01-01 UTC), call Math.random to pick a uniform value in that integer range, and convert back to a Date object. The conversion to calendar form respects the chosen output timezone (UTC by default, with optional local time display). Time-of-day randomization either truncates to midnight or distributes uniformly across the 24 hours of the chosen day.
A worked example: generating a random date between 2020-01-01 and 2024-12-31. The range spans 1,827 days or 157,852,800,000 milliseconds. Math.random produces a value scaled to that range, say 73,456,789,000 ms past the start, which converts to 2022-04-29 16:33:09 UTC. Setting the weekday filter to 'business days only' rejects weekend samples and resamples until a Monday-Friday hits, an acceptance ratio of 5/7 ≈ 71% per attempt. For most use cases, this is statistically equivalent to drawing from the business-day-only distribution directly.
Limitations are about distribution properties and randomness source. Uniform distribution across milliseconds in the range produces near-uniform dates, with months of fewer days slightly under-represented (February gets 28-29 millisecond-quanta vs March's 31). The bias is below 0.1% for typical multi-year ranges. Math.random is the default randomness source, suitable for casual use (picking a meeting day, sampling a date for testing) but inappropriate for security-sensitive applications. Lottery-style fair selection or anything where prediction matters should use Web Crypto's getRandomValues to populate the sample.
Weekday filtering uses rejection sampling rather than direct generation from the filtered set. For very narrow ranges where most days fall outside the filter (e.g., a 7-day range with 'Mondays only'), efficiency drops since 6 of 7 samples are rejected, but correctness is preserved. Holidays are not built in; for region-specific holiday exclusion, an external calendar source (ical feed, government holiday list) would need to be cross-referenced. Timezone handling is UTC internally with display optionally in local time; this avoids the ambiguity of dates that span midnight in some zones but not others, particularly relevant near DST transitions.
Applications include generating test data with realistic date variation, picking random review dates for QA cycles, scheduling probability experiments, and producing fair lottery-style date selections. For each use, matching the randomness source to the stakes (Math.random for non-security, getRandomValues for fairness-critical) is the meaningful choice.
The about text and FAQ on this page were drafted with AI assistance and reviewed by a member of the Coherence Daddy team before publishing. See our Content Policy for editorial standards.