Error handling in date comapring function