Results 1 to 4 of 4

Thread: How to Calculate Age Using SQL

  1. #1
    Join Date
    Feb 2009
    Posts
    29

    How to Calculate Age Using SQL

    Hi everybody, I Have program in java. and a a table in sql which contains a field date_of_Birth . I would like to make a calculation on this date_of_Birth fields and displays the age of the person in java. the query I M Using is Query1 = "SELECT AVG (DATEDIFF (year, date_of_Birth, getdate ())) FROM Table 2 "; It worked in query analyzer and displays age. but when I try to Run in java. it does not. Does anyone have a java code or a class that allows me to do this? Thank you in advance.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to Calculate Age Using SQL

    Hello , You Can Try With These Sql codes for getting the age of a person :

    DECLARE @BirthDate DATETIME
    DECLARE @CurrentDate DATETIME

    SELECT @CurrentDate = '20070210', @BirthDate = '19790519'

    SELECT
    DATEDIFF(YY, @BirthDate, @CurrentDate) -
    CASE
    WHEN(
    (MONTH(@BirthDate)*100 + DAY(@BirthDate)) >
    (MONTH(@CurrentDate)*100 + DAY(@CurrentDate))
    ) THEN 1
    ELSE 0

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to Calculate Age Using SQL

    You can use a SELECT query rather than a cursor by substracting the birthdate from the system date. use different functions for determining the current date and for extracting parts of dates. For example, to retrieve the system date, DB2 uses CURRENT DATE, Oracle uses SYSDATE, SQL Server and Sybase use GETDATE.

  4. #4
    Join Date
    Sep 2009
    Posts
    1

    Re: How to Calculate Age Using SQL

    hi please help me iam student i know how to creat database in sql i dont know how can i make interface for sql

Similar Threads

  1. How to Calculate IOPS
    By ShankY.Rudeshwar in forum Windows Software
    Replies: 8
    Last Post: 30-12-2011, 10:24 PM
  2. Calculate IRR in Excel
    By superdave1984 in forum Windows Software
    Replies: 3
    Last Post: 01-12-2009, 12:46 PM
  3. How to calculate rwin
    By CRUZITA in forum Networking & Security
    Replies: 3
    Last Post: 06-08-2009, 12:29 PM
  4. How to calculate Avg,Min and Max with SQL Plus
    By B_Hodge in forum Software Development
    Replies: 2
    Last Post: 29-05-2009, 01:08 PM
  5. How to calculate substitution
    By $tatic in forum Software Development
    Replies: 3
    Last Post: 25-04-2009, 08:42 PM

Tags for this Thread

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
  •  
Page generated in 1,751,658,907.85487 seconds with 16 queries