RSS Forums RSS
Please support our MS SQL advertiser: Programming Forums
Views: 4101 | Replies: 5 | Solved
Reply
Join Date: Jul 2005
Posts: 4
Reputation: blindmancries is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
blindmancries blindmancries is offline Offline
Newbie Poster

How do I calculate ages

  #1  
Jul 22nd, 2005
I need a help.

I have a SQL SERVER database where I have put persons with their birthdate. I need to calculate ages of them. For examble my birthdate is 12/27/1982 and I have to debit (minus) from current date.

Does anyone have any idea how to solve this problem.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 25
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: How do I calculate ages

  #2  
Jul 22nd, 2005
Use the SQL DATEDIFF function.

DATEDIFF( datapart, date_expression1, date_expression2)

i.e.
DATEDIFF (year, '1/1/1999', '1/1/2000')   

 would give 1 as a result 

Hope that helps

Happy coding
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
Join Date: May 2005
Location: London, UK
Posts: 145
Reputation: Electrohead is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
Electrohead's Avatar
Electrohead Electrohead is offline Offline
Junior Poster

Re: How do I calculate ages

  #3  
Jul 22nd, 2005
Sounds tricky! Maybe you could adapt a javascript to suit your needs?
: :: Click here to join my website :: :
Brand new online community! Help my forum grow!
Reply With Quote  
Join Date: Feb 2003
Location: Canada
Posts: 786
Reputation: Paladine has a spectacular aura about Paladine has a spectacular aura about Paladine has a spectacular aura about 
Rep Power: 9
Solved Threads: 25
Colleague
Paladine's Avatar
Paladine Paladine is offline Offline
Master Poster

Re: How do I calculate ages

  #4  
Jul 22nd, 2005
Tricky?

And what does Javascript have to do with SQL functions?

The function is simple.... how is it tricky?


Originally Posted by Electrohead04
Sounds tricky! Maybe you could adapt a javascript to suit your needs?
Assistant Manager, Regional Pharmacy Information Systems
TLC Services Website (Under Construction)
Updated : ASP.Net Login Code
Reply With Quote  
Join Date: Jul 2005
Posts: 4
Reputation: blindmancries is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
blindmancries blindmancries is offline Offline
Newbie Poster

Re: How do I calculate ages

  #5  
Jul 25th, 2005
I still get error on calculation, but it is syntax error.

Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near 'year'.

Where could be the problem.
Reply With Quote  
Join Date: Jul 2005
Posts: 4
Reputation: blindmancries is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
blindmancries blindmancries is offline Offline
Newbie Poster

Re: How do I calculate ages

  #6  
Jul 25th, 2005
Anyway thanks I already fixed the problem. Thnaks a lot
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:36 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC