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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling Date Specific Records 1

Status
Not open for further replies.

bigairguy

Programmer
May 10, 2005
14
US
Please take it easy on me as I am still quite novice at SQL. I have a SQL Server database in which I have a field DATE_CREATED. What I am trying to do is select all fields that have a DATE_CREATED value within the last two months. This is my SQL statement:

SELECT * FROM tbl_group

WHERE DATE_CREATED >= ('now'::datetime - '2 months'::timespan)

I read somewhere that timespan is fairly robust in that it recognizes phrases such as '2 months,' '12 hours,' etc. I get an error near one of the colons. Any help would be greatly appreciated.

Thanks,
Patrick
 
I suggest you post in one of the SQL Server forum.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Code:
SELECT *
FROM table
WHERE datecreated >= DATEADD(mm, -2, GETDATE())

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top