Missing Century in Date

  • SQLSeTTeR (7/31/2014)


    Eirikur worked perfect. It did exactly what I needed it to do. Thanks again! 😀

    What about 7/26/19?

    declare @mycutoff date = '01/01/2020';

    select [Date] = CONVERT(VARCHAR(10),CASE WHEN convert(datetime,'7/26/19',1) >= @mycutoff THEN DATEADD(YEAR,-100,convert(datetime,'7/26/19',1)) ELSE convert(datetime,'7/26/19',1) END,103)

    The SQL Guy @ blogspot[/url]

    @SeanPearceSQL

    About Me[/url]

  • I'm using:

    DECLARE @CutOff DATE

    SET @CutOff = '01/01/2016'

  • Ok, I just have to toss a wrench into the logic here.

    Since we are talking about birthdays, what if the person is over 100 years old? This logic will fail.

  • What type of data is being stored in the database? What is the application it is supporting?

  • DOB

  • kherald69 (8/8/2014)


    Ok, I just have to toss a wrench into the logic here.

    Since we are talking about birthdays, what if the person is over 100 years old? This logic will fail.

    It will fail in the same manner as any other attempt to measure beyond the scale implied. This has to be adjusted in the way that majority of the set is covered.

    😎

  • Edit: Duplicate

  • SQLSeTTeR (8/8/2014)


    DOB

    It is was obvious that one of the data elements is DOB but that didn't answer the question.

  • My apologies.

    It's a DOB field being stored as a string. No application is pointing to this data.

    Any help is much appreciated.

  • SQLSeTTeR (8/9/2014)


    My apologies.

    It's a DOB field being stored as a string. No application is pointing to this data.

    Any help is much appreciated.

    First, do not store dates as strings. Use the appropriate data type, and since you appear to be on SQL Server 2008 that would be DATE.

    So you have an entire database with one table storing DOBs, why?

Viewing 10 posts - 16 through 24 (of 24 total)

You must be logged in to reply to this topic. Login to reply