I need some quick SQL help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Socks
    Confirmed User
    • May 2002
    • 8475

    #1

    I need some quick SQL help

    In one table named AD I have a date_of_birth field, saved like 1970/01/30
    In another table named AQ I have quote_date saved like 2009/01/30

    I want to create a new column in AD called "age" and save how old they were when they got the quote.

    So on January 30th, 2009, they were 39 years old. I want to save "39" to a new field in the same row as date_of_birth.

    Important note: Both fields are strings, not date fields. :/

    Oracle, but most SQL statements work.. Also doesn't need to be to-the-day accurate.

    How do I do this?
    Last edited by Socks; 02-03-2013, 08:49 PM.
  • sarettah
    see you later, I'm gone
    • Oct 2002
    • 14298

    #2
    What you want is the same as the DateDiff() function in sql server but Oracle does not have a DateDiff function.

    Here is a solution I found for getting days, hours, minutes: http://asktom.oracle.com/pls/asktom/...42712657900129

    I would usually use a DateDiff() that returned months and then divide them by 12 to get the age. Not sure of the best way to do that in Oracle.

    As far as the dates being strings you should be able to cast them as dates.

    Hope that helps.

    .
    Last edited by sarettah; 02-04-2013, 05:46 AM.
    All cookies cleared!

    Comment

    • sarettah
      see you later, I'm gone
      • Oct 2002
      • 14298

      #3
      Here is a beter solution http://stackoverflow.com/questions/3...irth-and-today

      .
      All cookies cleared!

      Comment

      Working...