Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-04-2009
Member
 
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.
Reply With Quote
  #2  
Old 06-04-2009
Member
 
Join Date: Jan 2008
Posts: 1,515
Re: How to Calculate Age Using SQL

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

Quote:
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
Reply With Quote
  #3  
Old 06-04-2009
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
  #4  
Old 16-09-2009
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 06:13 AM.