The base date as a Date object or timestamp (number)
The number of hours to subtract (can be negative to add)
A new Date object with the hours subtracted, or Invalid Date if any input is invalid
// Subtract positive hours
const result = subHours(new Date(2025, 0, 15, 18, 0, 0), 5);
// Returns: 2025-01-15 13:00:00
// Add hours (negative amount)
const result = subHours(new Date(2025, 0, 15, 10, 30, 0), -3);
// Returns: 2025-01-15 13:30:00
// Fractional amounts are truncated
const result = subHours(new Date(2025, 0, 15, 15, 0, 0), 1.9);
// Returns: 2025-01-15 14:00:00 (1.9 truncated to 1)
// Crosses day boundary
const result = subHours(new Date(2025, 0, 15, 2, 0, 0), 4);
// Returns: 2025-01-14 22:00:00
// Invalid inputs return Invalid Date
const result = subHours(new Date("invalid"), 3);
// Returns: Invalid Date
Subtract the specified number of hours from the given date.
This function validates arguments before processing and returns a new Date instance with the specified number of hours subtracted. Fractional hours are truncated toward zero. Minutes, seconds, and milliseconds are preserved.