select * from Customers c
where dateadd(year, 1900-year(dob), dob)
between dateadd(year, 1900-year(getdate()), getdate())
and dateadd(year, 1900-year(getdate()), getdate())+7
The above Query Displays next 7 days up coming birthdayswhere dateadd(year, 1900-year(dob), dob)
between dateadd(year, 1900-year(getdate()), getdate())
and dateadd(year, 1900-year(getdate()), getdate())+7
——————————————————————-
Calculating Age of a Person
SELECT * FROM Employee WHERE DATEDIFF(dd, DATEADD(yy, -(DATEPART(yy,GETDATE())-1900),GETDATE()), --Today DATEADD(yy, -(DATEPART(yy,BirthDate)-1900),BirthDate) ) BETWEEN 1 AND 10
No comments:
Post a Comment