SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: how to calculate age on the fly during a select statement

  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to calculate age on the fly during a select statement

    Is there a way to calculate age on the fly during a select statement based off of a date of birth field?

  2. #2
    SitePoint Enthusiast
    Join Date
    Dec 2011
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is what I have so far:
    select name, year(date()-year(dob)) as age
    from users;

  3. #3
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,456
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

Bookmarks

Posting Permissions

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