Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 4th, 2004, 06:15 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calculating and filtering age based on date

I have a SQL DB with a table that contains a "YEAR" column. I also have a ASP.NET web form with two drop down fields, looks like this:

AGE: Between [18] and [25]

[18] and [25] being drop down boxes

I would like to know what SQL math funciton in combination with the TSQL date functions I can use to calculate and filter this data. I also have a MONTH column and a DAY column that would need to be included in the query to produce an accurate result, i guess.

Thanks,

-- shawn

Reply With Quote
  #2 (permalink)  
Old August 5th, 2004, 07:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

What result do you want to produce? Do you want to see who was born between those age limits? If so, subtract 18 and 25 from the year to find the year range, and select everyone in between.

Brian
Reply With Quote
  #3 (permalink)  
Old August 5th, 2004, 08:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Shawn,

It would always be tedious for you to produce that exact result you are looking for with this kind of setup. As SQL itself has a DATETIME datatype, from which you can produce this exact result with less effort. I feel you have complicated things by having the Year/Month/Day as different columns. Merge them together, you can easily achieve that.
Code:
Select * from TableName where datediff(yy,AgeColumnName, getdate()) BETWEEN 18 and 25
Is that NOT so easy?

Else you will have to do all that calculations yourself from each year and then month and then day from your table... that is something really I can't think about.

Hope this helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
  #4 (permalink)  
Old August 5th, 2004, 12:11 PM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DateDiff; those SQL pioneers have though of everything. That function is exactly what I was looking for. Thanks Vijay!

Reply With Quote
  #5 (permalink)  
Old November 12th, 2005, 06:08 AM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

-- Be careful with DateDiff yy - that just returns the years between two dates and *not* elapsed time. Consider:

SELECT DateDiff(yy,'12/31/2000','1/1/2005') AS YearDiff, FLOOR(DateDiff(dd,'12/31/2000','1/1/2005')/365.25) As CloserToCorrect

/*
YearDiff returns 5, 2005-2000. This answer is incorrect, our example person just had their 4th birthday the day before.
The CloserToCorrect field gets us a lot closer to an accurate age of 4.
Date / Age
12/31/2000 / 0
12/31/2001 / 1
12/31/2002 / 2
12/31/2003 / 3
12/31/2004 / 4
12/31/2005 / 5
*/

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering the list between the date range sea_aiko SharePoint Development 1 August 7th, 2008 04:21 PM
filtering date in Sharepoint sea_aiko ActionScript 0 April 4th, 2008 12:07 PM
Select fields & calculating age miki-pt Access ASP 1 November 26th, 2006 06:16 PM
calculating a persons age Hudson40 Access VBA 4 January 26th, 2005 11:45 AM
Calculating a field based on a lookup range nrwatson Access VBA 1 April 29th, 2004 06:41 PM



All times are GMT -4. The time now is 09:25 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.