473,943 Members | 19,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PLease Help Get Age FRom DAte

Im making this stored procedure to return the age of the user to the web
control but the problem is that DATEPART(). I can only Specify one and i need
the age to to the exact format of mm dd yy but i cant get it into the Query
so it can execute. And when I use the yyyy to return the Age it returns the
age as between 1 - 11 months and between 1 - 364 days. So for example the
user was
borned 21.11.85. when executed it returns the user is 20 when their 20th is
4months away.

<SQL QUERY>
SELECT DATEDIFF(yyyy, Dob, GETDATE()) AS Age
FROM Basic
WHERE (UName = @UName)

Nov 22 '05 #1
3 1461
I'm not sure this would be acceptable in your situation as it's not exact -
but why not get the number of days old they are and divide by 365. That
should get you a years value that reflects the fact they may not have hit
their birthday yet this year.

Of course leap years throw this calculation off, but still should be pretty
close.

"eamon" wrote:
Im making this stored procedure to return the age of the user to the web
control but the problem is that DATEPART(). I can only Specify one and i need
the age to to the exact format of mm dd yy but i cant get it into the Query
so it can execute. And when I use the yyyy to return the Age it returns the
age as between 1 - 11 months and between 1 - 364 days. So for example the
user was
borned 21.11.85. when executed it returns the user is 20 when their 20th is
4months away.

<SQL QUERY>
SELECT DATEDIFF(yyyy, Dob, GETDATE()) AS Age
FROM Basic
WHERE (UName = @UName)

Nov 22 '05 #2
hi

was this a repeated post? included your correction
SELECT DATEDIFF(d, Dob, GETDATE()) / 364 AS Years,
( 12 - ( datepart(m, dob) - datepart(m,getd ate()))) % 12 AS Months
FROM Basic
WHERE (UName = @UName)

--
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.SQLResource.com/
---------------------------------------

"eamon" wrote:
Im making this stored procedure to return the age of the user to the web
control but the problem is that DATEPART(). I can only Specify one and i need
the age to to the exact format of mm dd yy but i cant get it into the Query
so it can execute. And when I use the yyyy to return the Age it returns the
age as between 1 - 11 months and between 1 - 364 days. So for example the
user was
borned 21.11.85. when executed it returns the user is 20 when their 20th is
4months away.

<SQL QUERY>
SELECT DATEDIFF(yyyy, Dob, GETDATE()) AS Age
FROM Basic
WHERE (UName = @UName)

Nov 22 '05 #3
Hi

just check this. this can help u further:
http://chanduas.blogspot.com/2005/08...ating-age.html

--
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.SQLResource.com/
---------------------------------------

"eamon" wrote:
Im making this stored procedure to return the age of the user to the web
control but the problem is that DATEPART(). I can only Specify one and i need
the age to to the exact format of mm dd yy but i cant get it into the Query
so it can execute. And when I use the yyyy to return the Age it returns the
age as between 1 - 11 months and between 1 - 364 days. So for example the
user was
borned 21.11.85. when executed it returns the user is 20 when their 20th is
4months away.

<SQL QUERY>
SELECT DATEDIFF(yyyy, Dob, GETDATE()) AS Age
FROM Basic
WHERE (UName = @UName)

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1652
by: David Goodyear | last post by:
At the moment im experimenting with ideas in C++ and would really like to solve the following, please please help. Sorry i dont even know what the subject is this would come under? :( Sorry if this is elsewhere in the newsgroup & please reply with links to threads or something? (I dont know what to look for :( ) (Terms are prob. all wrong as well :( ) The problem: I have a data structure represented by a class. Use a date class as an
2
1935
by: Giulio | last post by:
I make an import of a huge file txt table with headers at each page and date format as "20.12.2004" in order to use the data I first qo a query that exclude all line representing the headers repeated for each page. now that I have a txt table with several colums I convert back the comlumns in to the format I need to perform other table: I mainly have to convert text fields in to Dates and numbers.
22
2294
by: settyv | last post by:
Hi, I need to write a Javascript which calculates datedifference as well as date comparision.When i try to embed the below script,it is working well,but the page is submitting even when the condition evaluates to false .Please let me know the reason what is the problem in the below script. function ValidateDate()
5
2595
by: settyv | last post by:
Hi, Below is the Javascript function that am trying to call from asp:Button control. <script language="javascript"> function ValidateDate(fromDate,toDate) { var fromDate=new Date();
29
2927
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
0
3074
by: 2Barter.net | last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA Inbox Reply Reply to all Forward Print Add 2Barter.net to Contacts list Delete this message Report phishing Show original
9
3058
by: deaconj999 | last post by:
Hi All, I am using this unbound to add the frequency to a date entered =IIf(="HIGH - annual",+365,IIf(="MED - 3 yearly",+1095,IIf(="LOW - 5 yearly",+1825,IIf(="N/ A",Date())))) but would rather it take into account the leap year, I am using the medium date format in my database, I would rather not mess about
6
3337
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID, EmpName,DeptID,DateOfJoin, Sal, Addr) Finance (EmpID, Sal) Club (Clubname, EmpID, Fee, DateOfJoin) Leave (EmpID, Date) Department (DeptID, DeptName, NoOfEmployees)...
3
2056
osward
by: osward | last post by:
Hi, everyone, I had managed to make use of the date link from a simple calendar script to my query table. When I click on the date's link or Prev and Next Month link, The table first row will be that link's day and onwards. I have a problem with the page link part that it won't advance to the next page according but go back according to today's date. This is the calender script section // Display Calandar error_reporting('0'); ...
0
10143
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
9970
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
11539
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
11133
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...
0
9866
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8228
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7393
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6312
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4913
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.