AGE help

  • I am needing to select from ubirthdate from table1 all persons that are age 16 from a date range getdate() + 7.  I'm stuck.....can anyone help.  This is what I have and it DOES not work.

     

    select ubirthdate

    from contact2

     where CAST(substring(ubirthdate,4,3) AS Varchar) = CAST(substring(getdate(),4,3) AS Varchar)

     and CAST(substring(ubirthdate,1,2) AS Varchar) between

     CAST(substring(getdate(),1,2) AS Varchar) and CAST((substring(getdate(),1,2) + 7) AS Varchar)

     and (YEAR(getdate()) - YEAR(ubirthdate) = 16)

     

    HELP

  • Can you provide a schema and data example?



    Shamless self promotion - read my blog http://sirsql.net

  • Here is an example of the date in the contact2 table - column ubirthday

    1986-12-08 00:00:00.000

    1986-10-28 00:00:00.000

    1986-03-31 00:00:00.000

    1986-11-21 00:00:00.000

  • You're trying to get the birthdates off all people who are 16 and who's birthdays are in the next week?



    Shamless self promotion - read my blog http://sirsql.net

  • Everyone who is 16 within the week

  • Try this...

    select ubirthdate from contact2

    where dateadd(year, 16, ubirthdate)

     between convert(varchar(12), getdate()) and convert(varchar(12), dateadd(day, 7, getdate()))

     



    Shamless self promotion - read my blog http://sirsql.net

  • Thank you, Thank you, Thank you

Viewing 7 posts - 1 through 6 (of 6 total)

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