Overview
This prompt aims to guide the creation of a tool for calculating age from a birth date. Programmers and developers will benefit by having a structured approach to implement this functionality.
Prompt Overview
Purpose: This tool calculates age based on a provided birth date in various formats.
Audience: It is designed for developers and users needing accurate age calculations in applications.
Distinctive Feature: The tool handles edge cases, including leap years and various date formats, ensuring precise results.
Outcome: Users receive their age in years, with optional details on months and days for enhanced accuracy.
Quick Specs
- Media: Text
- Use case: Generation
- Industry: Data & Analysis, Productivity & Workflow
- Techniques: Zero-Shot Prompting
- Models: Claude 3.5 Sonnet, Gemini 2.0 Flash, GPT-4o, Llama 3.1 70B
- Estimated time: 5-10 minutes
- Skill level: Beginner
Variables to Fill
No inputs required — just copy and use the prompt.
Example Variables Block
No example values needed for this prompt.
The Prompt
Create a prompt for a language model to generate a tool that calculates age based on a given birth date.
### Steps
1. Receive Input:
– Ensure the input is in a valid date format, such as:
– YYYY-MM-DD
– MM-DD-YYYY
2. Calculate Current Age:
– Extract the year, month, and day from the input date.
– Compare these values with the current date to compute the age in years.
– Handle edge cases for month and day to accurately adjust the age calculation.
3. Output:
– Present the age in years, and optionally include months and days for greater precision.
### Output Format
– Return the age as:
– An integer
– A string stating the number of years (and optionally months and days) since the birth date.
– Example formats:
– “You are 29 years old.”
– “You are 29 years, 3 months, and 12 days old.”
### Example
**Input**: “1990-07-25”
**Output**: “You are 33 years old.” (as of 2023)
### Notes
– Ensure robust error handling for invalid date formats.
– Consider leap years in your calculations.
– Fix to a common standard date (e.g., UTC) to account for time zones if irrelevant.
Screenshot Examples
How to Use This Prompt
- Copy the prompt provided above.
- Paste the prompt into your language model interface.
- Run the prompt to generate the age calculation tool.
- Test the tool with various birth dates.
- Review the output for accuracy and format.
- Make adjustments as needed for edge cases.
Tips for Best Results
- Input Validation: Ensure the birth date is in a valid format (YYYY-MM-DD or MM-DD-YYYY) before processing.
- Age Calculation: Extract year, month, and day; compare with the current date to calculate age accurately.
- Output Formatting: Present the age clearly, e.g., “You are 29 years old.” or include months and days for precision.
- Error Handling: Implement robust checks for invalid dates and handle leap years appropriately in calculations.
FAQ
- How do you validate a birth date format?
Use regular expressions to check if the input matches YYYY-MM-DD or MM-DD-YYYY formats. - What is the first step in calculating age?
Extract the year, month, and day from the provided birth date input. - How do you handle edge cases in age calculation?
Adjust the age based on whether the current month and day are before or after the birth date. - What should the output include?
Return the age in years, and optionally include months and days for more detail.
Compliance and Best Practices
- Best Practice: Review AI output for accuracy and relevance before use.
- Privacy: Avoid sharing personal, financial, or confidential data in prompts.
- Platform Policy: Your use of AI tools must comply with their terms and your local laws.
Revision History
- Version 1.0 (February 2026): Initial release.


