Results 1 to 2 of 2

Thread: date validation

  1. #1
    Join Date
    Mar 2004

    Unanswered: date validation

    I am new to SQL SERVER,

    Can anybody help me to write a procedure to validate a given string like
    09461020(Y2K compliant date), I need to check wether this is a valida date or not??
    0946 = should convert to 1946
    10 = month
    20 is the date.

    If it is 20461020.....then year = 2046, month = 10 and day = 20..and it is valid.

    procedure should return validate date or not ...return TRUE OR FALSE.

  2. #2
    Join Date
    Jun 2003
    Provided Answers: 1
    You need to parse your string and pass it to the isdate() function.

    declare @DateString char(8)
    set @DateString = '09461020'

    isdate(cast(cast(left(@DateString, 4) as int) + 1000 as char(4))
    +'-'substring(@DateString, 5, 2)
    +'-'right(@DateString, 2))
    If it's not practically useful, then it's practically useless.

    blindman "sqlblindman"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts