473,770 Members | 4,718 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculating Age median from list of Dates of Birth

2 New Member
Hii friends

I need to calculate the age median from the given dates of birth in an employee database in MS SQl.

Please help...

Roma
Feb 12 '08 #1
5 7311
Delerna
1,134 Recognized Expert Top Contributor
do a datediff between the current date and their birth date
then take the average
for example in months it is
Expand|Select|Wrap|Line Numbers
  1. SELECT avg(datediff(m,getdate(),birthdate))
  2. FROM employees
  3.  
is that what you mean
Feb 12 '08 #2
deepuv04
227 Recognized Expert New Member
Hii friends

I need to calculate the age median from the given dates of birth in an employee database in MS SQl.

Please help...

Roma

Hi,


for calculating the age use the following sample query and change it according to your requirement


DECLARE @FromDate DATETIME,
@ToDate DATETIME

SELECT @FromDate = '1983-07-04',@ToDate = '2008-07-04'

SELECT CASE WHEN @FromDate > @ToDate THEN NULL
WHEN DATEPART(day, @FromDate) > DATEPART(day, @ToDate) THEN DATEDIFF(month, @FromDate, @ToDate) - 1
ELSE DATEDIFF(month, @FromDate, @ToDate)
END / 12.0


thanks
Feb 12 '08 #3
deepuv04
227 Recognized Expert New Member
do a datediff between the current date and their birth date
then take the average
for example in months it is
Expand|Select|Wrap|Line Numbers
  1. SELECT avg(datediff(m,getdate(),birthdate))
  2. FROM employees
  3.  
is that what you mean

Hi,

if the birth date is 2007-01-31 and today is 2008-02-01 and
in the code SELECT avg(datediff(m, getdate(),birth date))
FROM employees the function datediff(m,getd ate(),birthdate ) will give you the difference as 1 month though it is differ by 1 day.
Feb 12 '08 #4
Delerna
1,134 Recognized Expert Top Contributor
Hi,

if the birth date is 2007-01-31 and today is 2008-02-01 and
in the code SELECT avg(datediff(m, getdate(),birth date))
FROM employees the function datediff(m,getd ate(),birthdate ) will give you the difference as 1 month though it is differ by 1 day.

Then use days
avg(datediff(d, getdate(),birth date))
Feb 12 '08 #5
romanisa
2 New Member
Hey Thanks everyone for the code....
Feb 13 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2142
by: Neil Grantham | last post by:
I am creating a database for Nursery children, and part of the reporting requirement, is to show those on the waiting list. Children will be elligible for entry by age, and so based on their date of birth, I would like a report that has calculated which intake semester the child falls under. So, children born 1-Sep to 31-Dec are Autumn, 1-Jan to 31-Mar are Spring, and 1-Apr to 31-Aug are Summer Somewhere in my database I'd like to...
4
2648
by: Working_Girl | last post by:
Hi, I have a database with insurance clients and their dependents (spouses and children). We had a problem in the past with the twins and some of them have been entered with one month difference in their dates of birth, some of them have the same dates of births. I need to query both cases. In the case where they are set up with one month difference, the dates of birth has to be within 4 months of each other and excluding the ones...
5
9436
by: jonm4102 | last post by:
I'm trying to calculate the median of some numerical data. The data can only be found in a query (henceforth query 1) field I previously made, and I would prefer to calculate the median in a new query it without making a table out of query 1. I can't find a median function in the "Total" field, so is there so way to make an expression to calculate the median of the orignial data from query 1 in my new query? Also, what does name by...
8
17579
by: helpless | last post by:
Access 2003 - I am trying to calculate the difference between a specific date 5/1/2007 (not in a data field) and other dates that ARE in a field called Birth Date. I am trying to have it fill into an Age field (in years only) by comparing the date above to the Birth Date field. I have tried this and it doesn't work: =DateDiff("yyyy", , ) Displays the variance in years between the values of the Birthday1 and Birthday2 fields. (from Access...
3
12905
by: Emlyons | last post by:
Hello, I am completely new to Access. I am running a query but need to take the median value of observations in one of my tables. I've tried creating an expression but it is not working. I've also done some internet searching for a step by step guide on how to do this, but it's all jibberish to me! Could someone who has a few minutes to spare please post some sort of quick step by step guide on how to get median values in language that a...
2
3333
by: rn5a | last post by:
During registration, users have to provide their date of birth. For the date & month part, there are 2 dropdown lists & for the year, there's a textbox. These 3 fields are finally merged together to populate a MS-Access database table in a column named DOB whose data type is Date/Time. There's another page named, say, MyPage.asp, in the same application where users have to again enter their date of birth. Like the registration page,...
10
3290
by: Massimo30 | last post by:
Looking for answers and have done a search in books and websites and still can't find the answer: I am setting up a Market Trend DB on housing figures. I have the following fields in my table: My objective is to find the percent of change between this month and last month. Easy enough, but how do I set this up? It's not like excel where you can just enter the cell. Month (Jan,Feb,Mar, etc..) Year Market Trend Area SFR Median Sales...
3
1897
by: Hanoodah | last post by:
Good morning all, Please I need help in a form that I have designed to fill user information. This form needs two drop-down list about specific date, one about contract date, and the other about birth date. I am using java script function to display the dates, and use onload() function to set the drop-down list to the current date. I following error used to appear (null or not an object)!! Can any one help me in that? The code: ...
1
3550
by: cmb3587 | last post by:
My code runs fine for the most part...the only time it fails is when I type in a negative to end the array. I don't want the negative number to be included in the array and I thought that is what the while loop in the getNums method does. However, it is including this negative number when calculating the avg and it is doing something weird to the median. When the array end itself because the max size has been reached everything works fine. ...
0
9595
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9432
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5454
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3974
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.