Fix comparison error in datetime arithmetic function