Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
Programming
»
General
»
Correct Age calculation
Correct Age calculation
Rate Topic
Display Mode
Topic Options
Author
Message
jbalbo
jbalbo
Posted Friday, January 06, 2012 2:52 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Friday, June 14, 2013 8:02 AM
Points: 161,
Visits: 236
We are using the following to calculate age:
It doesn't seem correct ?
Any ideas would be great?
Thanks
Joe
INSERT INTO @TEMPTABLE(TAG_NAME,TAG_DATA)
SELECT TAG_NAME = 'CUST_AGE', TAG_DATA = (SELECT DATEDIFF (yy,bdate, GETDATE())FROM client
WHERE Client.OID =@CLIENT_OID);
Post #1231756
Dave Ballantyne
Dave Ballantyne
Posted Friday, January 06, 2012 2:59 PM
SSCommitted
Group: General Forum Members
Last Login: Tuesday, May 28, 2013 3:05 AM
Points: 1,943,
Visits: 8,229
Hi
Try this post from my blog
http://sqlblogcasts.com/blogs/sqlandthelike/archive/2009/12/08/age-calculation-with-sql-server.aspx
Clear Sky SQL
My Blog
Kent user group
Post #1231759
padhis
padhis
Posted Saturday, January 07, 2012 10:42 AM
SSC Journeyman
Group: General Forum Members
Last Login: Wednesday, February 01, 2012 3:57 AM
Points: 91,
Visits: 125
Here is good article for calculating age.
http://www.sqlservercentral.com/articles/T-SQL/63351/
Post #1231929
jbalbo
jbalbo
Posted Tuesday, January 10, 2012 9:00 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Friday, June 14, 2013 8:02 AM
Points: 161,
Visits: 236
Thanks,
That works great, but Im new at SQL and have tried but can't get the syntax right..
What if I wanted to select bdate from the "Client" file as date1 and getdate() as date2 ?
Thanks
Joe
Post #1233312
jshahan
jshahan
Posted Thursday, January 12, 2012 7:25 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Wednesday, June 12, 2013 4:18 PM
Points: 140,
Visits: 734
This is how I do it...
select c.clientid, convert(char(10),c.dateofbirth,101) as DOB,
case
when ((MONTH(c.dateofbirth) * 100) + DAY(c.dateofbirth)) > ((MONTH(getdate()) * 100) + DAY(getdate()))
then DATEDIFF(year,c.dateofbirth,getdate()) - 1
else DATEDIFF(year,c.dateofbirth,getdate()) End As Age
from clients c
Post #1234806
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.