Made to_date function more safe (#51)