Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date fields

Author  Topic 

micky--4444
Starting Member

19 Posts

Posted - 2010-06-07 : 07:43:54
I have constructed a test SQL Query. I run it through query analyser and it appears to work for the code below.

SELECT Users.*, aspnet_Membership.Email FROM Users INNER JOIN
aspnet_Membership ON Users.UserID=aspnet_Membership.UserID WHERE
DateofBirth < DateAdd(yy,-17,getDate())
AND DateofBirth > DateAdd(yy,-24,getDate())

The problem is that for one of the test dates I'm using to see if it works, the date is 1987-05-03 00:00:00.000

I don't understand how 1987-05-03 00:00:00.000 is less than DateAdd(yy,-17,getDate()), surely it should be greater than, as the date comes before. Shouldn't it? or am I missing something.

thanks.

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-06-07 : 07:52:46
Current year is 2010.
17 year less is 1993.. and 1987 is less than 1993... Isn't ?

I am here to learn from Masters and help new bees in learning.
Go to Top of Page

micky--4444
Starting Member

19 Posts

Posted - 2010-06-08 : 04:06:33
1987 is less than 1993... Isn't ?

Is it, I would have thought that a date of 1987 was greater than 1993, or maybe it's just treated as a number?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-08 : 05:01:44
quote:
Originally posted by micky--4444

1987 is less than 1993... Isn't ?

Is it, I would have thought that a date of 1987 was greater than 1993, or maybe it's just treated as a number?


Now, did you get correct result?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-08 : 05:06:42
Your own query
SELECT	DateAdd(yy,-24,getDate()),
DateAdd(yy,-17,getDate())
returns the following dates
1986-06-08	1993-06-08
I am pretty sure a date with year 1987 falls inbetween those two dates.


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -