#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Query - Age in Days from two existing dates


    I am in need of some guidance. I am needing to run a query that will allow me to get the Age of a person ( in days) at the time that they attended one of my events by using their DOB and the event date (mm/dd/yyyy).

    Anyone who can help me out with this?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    Simply use DATEDIFF:
    Code:
    SELECT DATEDIFF('2012-8-28', '2012-7-28');
    http://dev.mysql.com/doc/refman/5.5/...functions.html
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,

    Simply use DATEDIFF:
    Code:
    SELECT DATEDIFF('2012-8-28', '2012-7-28');
    Thanks for the help!

    I'm working with a large data set though, close to 5,000 individuals all of whom I need age in days for. Is there a way to run this on a large scale? I'm working with SQL in ACCESS 2010.

    Thanks again!
  6. #4
  7. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,178
    Rep Power
    4274
    Originally Posted by Jen2137
    Is there a way to run this on a large scale?
    yes, by replacing the hardcoded dates in the DATEDIFF example with actual column names, so that you process the entire table in one statement

    Originally Posted by Jen2137
    I'm working with SQL in ACCESS 2010.
    then you posted in the wrong forum

    fear not, i've moved your thread over

    fyi, you will have to look up the comparable function in access

    hint: it has a very similar name

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo