The base date as a Date object or timestamp (number)
The year as a number, or NaN if invalid
// Get year from Date object
const result = getYear(new Date(2025, 0, 15));
// Returns: 2025
// Get year from timestamp
const result2 = getYear(1704067200000); // 2024-01-01
// Returns: 2024
// Leap year
const result3 = getYear(new Date(2024, 1, 29));
// Returns: 2024
// Historic date
const result4 = getYear(new Date(1776, 6, 4));
// Returns: 1776
// Invalid date returns NaN
const result5 = getYear(new Date("invalid"));
// Returns: NaN
Get the full year of the given date.
This function validates arguments before processing and returns the full year (e.g., 2025) of the given date. Returns NaN for invalid input.