Condition with dates not working correctly