getYear
The `getYear` function extracts the year from a given date. If no date is provided, it defaults to the current date.> getYear(date?: Date | FixedDate | null): string
- date: Optional date to extract the year from, defaults to the current date. Accepts a Date object, a string in `YYYY-MM-DD` format, or null.
- Returns: The year as a string in `YYYY` format.
Example
import { getYear } from "@explita/daily-toolset";
// Default: current date
getYear(); // "2024" (if the current year is 2024)
// Specified date
getYear(new Date("1999-12-31")); // "1999"
// Using a fixed date string
getYear("2000-01-01"); // "2000"