in reply to DateTime and hour 0

Yes, $hour is set to 24, an out-of-range value. You should show where $hour gets its value for better advice.

After Compline,
Zaxo