Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateDiff Question 1

Status
Not open for further replies.

dvannoy

MIS
May 4, 2001
2,765
US
I have a field called date_expired I'm trying to run a query that will take the date_expired field and show records that will expire within 30 days from now.

any help would be appreciated

thanks

 
Code:
Select *
From   YourTable
Where  Date_Expired >= GetDate()
       And Date_Expired <= DateAdd(Day, 30, GetDate())

This should get you really close.

Please be aware that GetDate() includes date and time. If your date_expired column includes time information as well as date information, then you should be very careful about rows that expire in exactly 30 days.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top