Results 1 to 7 of 7

Thread: calculate birthdate

  1. #1
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139

    calculate birthdate

    I need to figure out who will be turning age 65 in april, may, or june, 2004.
    What should be the code, does anyopne know?

    Thanks.

  2. #2
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    select * from DOBTable where DOB >='04/01/'+convert(varchar(4),year(getdate())-65)
    and DOB<='06/30/'+convert(varchar(4),year(getdate())-65)

  3. #3
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    Hi Mak, it didn't work...

  4. #4
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    do u have a table with "Date of Birth" as column?


    select '04/01/'+convert(varchar(4),year(getdate())-65)

    --results 04/01/1939

    select '06/30/'+convert(varchar(4),year(getdate())-65)

    --results 06/30/1939

    --basically my query is doing the following
    select * from DOBTable where DOB >='04/01/1939'
    and DOB<='06/30/1939'

  5. #5
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    Yes I do, but my dob field is defined as char length of 8 and the data is in format 19850102 (year,month,date).

    Thx.

  6. #6
    Join Date
    Sep 2002
    Location
    Fantasy
    Posts
    4,254
    select convert(datetime,convert(varchar(4),year(getdate() )-65)+ '0401',112)

    --1939-04-01 00:00:00.000
    select convert(datetime,convert(varchar(4),year(getdate() )-65)+'0630',112)

    --1939-06-30 00:00:00.000

    select * from DOBTable where DOB >=convert(datetime,convert(varchar(4),year(getdate ())-65)+ '0401',112)
    and DOB<=convert(datetime,convert(varchar(4),year(getd ate())-65)+'0630',112)

  7. #7
    Join Date
    Oct 2002
    Location
    queens
    Posts
    139
    Thank you soooooooooo much, that worked.

Posting Permissions

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