• Ananth@Sql (7/22/2013)


    How To Validate a year, month,and date and totaldate?Year should be in yyyy format,month should be between

    1 and 1 to 12 and date should be between 1 to 31 and total date should be YYYY-MM-DD Formate?

    Plase guys share your ideas?

    What is an input for proposed validation?

    If it's one single character value, your best way would be just using ISDATE function.

    And about format. So, you want to be sure that if the date string provided, it is only in ISO format?

    (Please not that YYYYMMDD is also standard ISO format).

    I guess you can do some thing like that:

    DECLARE @validIsoDate BIT = 0

    IF ISDATE(@Value) = 1

    BEGIN

    IF CAST(YEAR(@Value) AS CHAR(4)) = LEFT(@Value,4) SET @validIsoDate =1

    END

    SELECT @validIsoDate

    The best option would be the above written as ITV function...

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]