date_betweenDatetime

Mock Jutsu HOW-TO | EN

The date_between function is a cornerstone utility within the mock-jutsu library, specifically designed to streamline the creation of chronological mock data. By generating a random date within a specified range, this tool allows developers to populate databases and API responses with realistic temporal information that mimics real-world user behavior. By default, the function selects a date from the past five years up to the current day, ensuring that the generated test data remains relevant to modern application contexts. Whether you are building a financial ledger, a content management system, or a social media timeline, having high-quality, randomized date-based information is critical for verifying system logic and UI consistency.

Under the hood, the date_between algorithm calculates the total duration between two boundary dates and applies a uniform distribution to select a random point in time. This mathematical approach ensures that the mock data is spread evenly across the timeline, preventing artificial clustering that could skew performance testing or analytical results. The function produces outputs in a standard format, such as 2022-06-12, making it highly compatible with various backend frameworks and relational databases. Developers can programmatically integrate this into their workflows using the Python API via jutsu.generate('date_between') or execute quick checks through the CLI command mockjutsu generate date_between, providing a seamless transition between local development and automated testing environments.

For performance engineers, mock-jutsu offers a specialized JMeter integration using the syntax ${__mockjutsu(date_between,)}, which allows for dynamic data generation during high-load simulations. This is particularly beneficial for testing scenarios such as historical data migration, where legacy systems require entries spanning specific decades, or for validating front-end date pickers and time-sensitive filtering logic. By utilizing date_between, teams can avoid the common pitfalls of hard-coded values that often lead to "stale" data errors or failed validation constraints. Instead, they gain a flexible, automated approach to creating comprehensive test data that reflects the inherent variability of production environments.

Ultimately, the primary benefit of using the date_between function is the significant reduction of manual effort in test data preparation. It empowers QA engineers and software developers to focus on core business logic and edge-case handling rather than the tedious task of manual date entry. By providing a reliable way to simulate user activity logs, subscription start dates, or transaction histories, mock-jutsu ensures that your testing environment is both robust and scalable. This function is an essential component for any developer looking to maintain high standards of data integrity and reliability throughout the software development lifecycle.

CLI Usage
mockjutsu generate date_betweenmockjutsu bulk date_between --count 10mockjutsu export date_between --count 10 --format jsonmockjutsu export date_between --count 10 --format csvmockjutsu export date_between --count 10 --format sqlmockjutsu generate date_between --start YYYY-MM-DD
Python API
from mockjutsu import jutsujutsu.generate('date_between')jutsu.bulk('date_between', count=10)jutsu.template(['date_between'], count=5)# with --start parameterjutsu.generate('date_between', start='YYYY-MM-DD')
JMeter
${__mockjutsu_datetime(date_between)}${__mockjutsu_datetime(date_between:2020-01-01|2024-12-31)}# JMeter Function: __mockjutsu_datetime# Parameter 1: date_between OR date_between:# Qualifier values: start|end (YYYY-MM-DD)# Parameter 2: (not required for this function)
REST API
GET /generate/date_between# → {"type":"date_between","result":"...","status":"ok"}GET /bulk/date_between?count=10POST /template {"types":["date_between"],"count":1}

Parameters

Parameter Values Description
--start YYYY-MM-DD Start date for date_between
--end YYYY-MM-DD End date for date_between

Other Languages