Wednesday, 28 August 2013

How do I check for specific date format?

How do I check for specific date format?

I am having issues with dates. The problem is, ISDATE will give me dates
that are valid even though the format is different. However, what I would
like to do is INSERT NULL is any date field not formatted like: 8/28/2013
or 08/28/2013
This is for international use. And for U.S Use only. This means:
08/08/2013 will mean August 8th 2011. And Will Cast as 2011-08-08.
I am not sure how to check for the format. I can do the whole CASE WHEN.
I tried playing around like this:
DECLARE @d DATETIME = '10/01/2011';
SELECT CASE WHEN @d != FORMAT ( @d, 'yyyy/MM/dd', 'en-US' ) THEN @d ELSE
NULL END
The dates currently in the column are format like so. 8/28/2013 or
08/28/2013 And I would do a cast if the format is correct.
Thanks!

No comments:

Post a Comment