addDays
A utility function to add or subtract a specified number of days to/from a given date.> addDays(days: number, date: Date = new Date()): Date
- days (number): The number of days to add. Pass a negative number to subtract days.
- date (Date, optional): The base date to modify. Defaults to the current date (new Date()).
- Returns: A new Date object with the specified number of days added.
Example
import { addDays } from "@explita/daily-toolset";
// Add 10 days to the current date
const futureDate = addDays(10);
console.log(futureDate); // e.g., 2024-12-02T00:00:00.000Z
// Subtract 5 days from a specific date
const pastDate = addDays(-5, new Date("2024-11-10"));
console.log(pastDate); // e.g., 2024-11-05T00:00:00.000Z
// Add 30 days to a specific date
const customDate = new Date("2024-01-01");
const result = addDays(30, customDate);
console.log(result); // e.g., 2024-01-31T00:00:00.000Z
Use Cases
- Calculating future or past dates based on a reference.
- Scheduling events or reminders.
- Adjusting dates for calendar calculations.