i want to make a select, where the users birthday(date field) is less than 30 days.
what is the best way to to do it? i tried datediff, but i don’t know how to put the year aside.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could just use
DATEPARTfunction withdayofyeardatepart value.EDIT: honestly, there is a boundary issue in my previous answer (many thanks to Damien): e.g.
2010-12-25and2011-01-07=> the difference should be less then 30 days, butDATEPART(dayofyear, @date) - DATEPART(dayofyear, [Birthday]) < 30condition would skip this record. So I added an additional contition to my answer:it adds one month to the each date in the case when the month part of the first date is December and compares the difference.