Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Calculating Age


Calculating Age

Author
Message
C# Gnu
C# Gnu
SSC Veteran
SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)

Group: General Forum Members
Points: 255 Visits: 659
jcrawf02 (3/13/2009)
Richard Briggs (3/13/2009)
Comrades,

Around one's birthday, we can be 16 in the UK, but still 15 in the US.

Worth mentioning as may be relevant to certain age verification web applications.

Brigzy

16:36 UK GMT


sp_MSGoBackInTime strikes again. How can you possibly be 16 in the UK and 15 in the US, unless you're talking about the timezone difference?


Yes the TimeZone difference.

C# Gnu
____________________________________________________


Excel Database Tasks : efficient business data processing
Version 3.3 released February 2015

jcrawf02
jcrawf02
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1424 Visits: 19324
Richard Briggs (3/13/2009)
jcrawf02 (3/13/2009)
Richard Briggs (3/13/2009)
Comrades,

Around one's birthday, we can be 16 in the UK, but still 15 in the US.

Worth mentioning as may be relevant to certain age verification web applications.

Brigzy

16:36 UK GMT


sp_MSGoBackInTime strikes again. How can you possibly be 16 in the UK and 15 in the US, unless you're talking about the timezone difference?


Yes the TimeZone difference.


Would that really be relevant, even to web verification apps? (Not trying to be contentious, just curious). If the user is going to be the required age in a matter of hours, does it really matter if you allow them access?

---------------------------------------------------------
How best to post your question
How to post performance problems
Tally Table:What it is and how it replaces a loop

"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
C# Gnu
C# Gnu
SSC Veteran
SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)

Group: General Forum Members
Points: 255 Visits: 659
jcrawf02 (3/13/2009)
Richard Briggs (3/13/2009)
jcrawf02 (3/13/2009)
Richard Briggs (3/13/2009)
Comrades,

Around one's birthday, we can be 16 in the UK, but still 15 in the US.

Worth mentioning as may be relevant to certain age verification web applications.

Brigzy

16:36 UK GMT


sp_MSGoBackInTime strikes again. How can you possibly be 16 in the UK and 15 in the US, unless you're talking about the timezone difference?


Yes the TimeZone difference.


Would that really be relevant, even to web verification apps? (Not trying to be contentious, just curious). If the user is going to be the required age in a matter of hours, does it really matter if you allow them access?


I guess it depends on the application, may be relevant to birthday money transfers, birthday card emails sites etc.

C# Gnu
____________________________________________________


Excel Database Tasks : efficient business data processing
Version 3.3 released February 2015

Andrew in WV
Andrew in WV
SSC-Enthusiastic
SSC-Enthusiastic (139 reputation)SSC-Enthusiastic (139 reputation)SSC-Enthusiastic (139 reputation)SSC-Enthusiastic (139 reputation)SSC-Enthusiastic (139 reputation)SSC-Enthusiastic (139 reputation)SSC-Enthusiastic (139 reputation)SSC-Enthusiastic (139 reputation)

Group: General Forum Members
Points: 139 Visits: 1374
Richard Briggs (3/13/2009)
I guess it depends on the application, may be relevant to birthday money transfers, birthday card emails sites etc.


Perhaps, but everyone isn't born at midnight either, so you would need to store a full timestamp of the birthdate including timezone information. I doubt any of those types of applications have that level of detail.

Andrew

--Andrew
jcrawf02
jcrawf02
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1424 Visits: 19324
Andrew (3/13/2009)
Richard Briggs (3/13/2009)
I guess it depends on the application, may be relevant to birthday money transfers, birthday card emails sites etc.


Perhaps, but everyone isn't born at midnight either, so you would need to store a full timestamp of the birthdate including timezone information. I doubt any of those types of applications have that level of detail.

Andrew


I wasn't born yesterday . . .

. . . gotta get up early to pull one over on me . . .

and other assorted cliche'sBigGrin

---------------------------------------------------------
How best to post your question
How to post performance problems
Tally Table:What it is and how it replaces a loop

"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
Mark Wiley-448637
Mark Wiley-448637
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 31
Here is what I use:

SELECT EMPLOYID, BRTHDATE,

CASE
WHEN DATEPART(day, BRTHDATE) > DATEPART(day, getdate()) THEN DATEDIFF(month, BRTHDATE, getdate()) - 1
ELSE DATEDIFF(month, BRTHDATE, getdate())
END / 12 AS [Age]

FROM

-Mark
C# Gnu
C# Gnu
SSC Veteran
SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)SSC Veteran (255 reputation)

Group: General Forum Members
Points: 255 Visits: 659
Andrew (3/13/2009)
Richard Briggs (3/13/2009)
I guess it depends on the application, may be relevant to birthday money transfers, birthday card emails sites etc.


Perhaps, but everyone isn't born at midnight either, so you would need to store a full timestamp of the birthdate including timezone information. I doubt any of those types of applications have that level of detail.

Andrew


I wouldn't store timestamp:

Suppose AutoBirthdaySurprise.com, and received a request to send money and an 'ecard' to little Tommy in Aukland Wellington, if I was hosting in the UK and didn't account for the timezone difference little tommy wouldn't get his card or his money until after 1pm w00t

C# Gnu
____________________________________________________


Excel Database Tasks : efficient business data processing
Version 3.3 released February 2015

jcrawf02
jcrawf02
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1424 Visits: 19324
Richard Briggs (3/13/2009)
I wouldn't store timestamp:

Suppose AutoBirthdaySurprise.com, and received a request to send money and an 'ecard' to little Tommy in Aukland Wellington, if I was hosting in the UK and didn't account for the timezone difference little tommy wouldn't get his card or his money until after 1pm w00t


How spoiled is little Tommy? You're sending him money, and he wants his 14 hours of interest?

---------------------------------------------------------
How best to post your question
How to post performance problems
Tally Table:What it is and how it replaces a loop

"stewsterl 80804 (10/16/2009)I guess when you stop and try to understand the solution provided you not only learn, but save yourself some headaches when you need to make any slight changes."
DPhillips-731960
DPhillips-731960
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1158 Visits: 801
Peso (6/30/2008)

E 12°55'05.25"
N 56°04'39.16"


Lingongatan?
deanroush
deanroush
SSC Rookie
SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)SSC Rookie (30 reputation)

Group: General Forum Members
Points: 30 Visits: 265
This method includes a form of "every 4 years" leap year support. It assumes a lifetime will rarely exceed 99 years and so foregoes making allowances for the 100 year (and beyond) leap year aberrations. In addition, this method can be easily used directly in a select statement. Of course the floating point math will not yield maximum performance. Opinions on this are greatfully solicited.

DECLARE @Years INT
DECLARE @DOB DATETIME
DECLARE @Compare DATETIME

SELECT @Years = ROUND((CONVERT(FLOAT,DATEDIFF(DAY,@DOB,@Compare)) - CONVERT(FLOAT,DATEDIFF(YEAR,@DOB,@Compare)) / CONVERT(FLOAT,4)) / CONVERT(FLOAT,365),0,3)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search