code to deal with bad dates