Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««56789»»»

Calculating Age Expand / Collapse
Author
Message
Posted Friday, March 13, 2009 10:49 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, August 15, 2014 12:07 PM
Points: 225, Visits: 645
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
____________________________________________________


Multi user data edit / data transfer Excel Task based solution
Version 2.7 released June 2013
Post #675417
Posted Friday, March 13, 2009 10:54 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:59 AM
Points: 2,670, Visits: 19,241
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."
Post #675422
Posted Friday, March 13, 2009 11:09 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, August 15, 2014 12:07 PM
Points: 225, Visits: 645
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
____________________________________________________


Multi user data edit / data transfer Excel Task based solution
Version 2.7 released June 2013
Post #675438
Posted Friday, March 13, 2009 11:42 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, July 24, 2014 11:16 AM
Points: 133, Visits: 1,269
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
Post #675465
Posted Friday, March 13, 2009 11:48 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:59 AM
Points: 2,670, Visits: 19,241
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's:D


---------------------------------------------------------
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."
Post #675469
Posted Friday, March 13, 2009 11:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, June 25, 2013 8:31 AM
Points: 3, Visits: 18
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
Post #675471
Posted Friday, March 13, 2009 11:53 AM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Friday, August 15, 2014 12:07 PM
Points: 225, Visits: 645
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


C# Gnu
____________________________________________________


Multi user data edit / data transfer Excel Task based solution
Version 2.7 released June 2013
Post #675473
Posted Friday, March 13, 2009 11:55 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 8:59 AM
Points: 2,670, Visits: 19,241
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


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."
Post #675475
Posted Friday, March 13, 2009 12:14 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Friday, August 10, 2012 6:08 PM
Points: 1,156, Visits: 801
Peso (6/30/2008)

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


Lingongatan?
Post #675492
Posted Friday, March 13, 2009 2:10 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, May 2, 2013 9:10 PM
Points: 26, Visits: 263
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)
Post #675564
« Prev Topic | Next Topic »

Add to briefcase «««56789»»»

Permissions Expand / Collapse