The base date as a Date object or timestamp (number)
The day to set (1-31, fractions are truncated)
A new Date object with the day set, or Invalid Date if any input is invalid
// Set day to 1st
const result = setDay(new Date(2025, 0, 15), 1);
// Returns: 2025-01-01
// Set day to last day of month
const result2 = setDay(new Date(2025, 0, 15), 31);
// Returns: 2025-01-31
// Day overflow (Jan 32 → Feb 1)
const result3 = setDay(new Date(2025, 0, 15), 32);
// Returns: 2025-02-01
// Fractional day is truncated
const result4 = setDay(new Date(2025, 0, 15), 15.9);
// Returns: 2025-01-15
// Invalid date returns Invalid Date
const result5 = setDay(new Date("invalid"), 15);
// Returns: Invalid Date
Set the day of the month of the given date.
This function validates arguments before processing and returns a new Date instance with the specified day set. Fractional days are truncated toward zero.