Made refinements to datetime checking. Thanks zcorpan.