pull the last 3 months of data

how can i pull the last 3 months of data from today's date.  I have something like this:

TimeStamp                                                 ScriptName
2010-07-26 09:16:44.000          SS_Script
2010-05-27 09:35:08.000              AE_Col
2010-02-27 09:40:07.000                                 AM_Br
Who is Participating?
dwe761Connect With a Mentor Software EngineerCommented:
Boy, you do have a puzzling situation.
I apologize if my questions will seem obvious but I have to ask anyway because the query I gave you works fine for me.

Could you generate the script for your table and post it?
Please post the exact query you ran.

Is it possible your system date got goofed up?
Try this:
Select dateadd(m, -3, getdate()) as MyMinDate
Is it what you'd expect?

Are you sure you're looking at the correct database when you check the data type of your Timestamp field?
DavidMorrisonConnect With a Mentor Commented:

try this

select TimeStamp, ScriptName
from <Insert Table Name Here>
where TimeStamp between getdate() and dateadd(mm, -3, getdate())


dwe761Software EngineerCommented:

select * FROM [YourTable]  where TimeStamp  >= dateadd(m, -3, getdate())
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

karinos57Author Commented:
it is not returning any data even though i have data.  i want to see anything for the last 3 months.  thanks
dwe761Software EngineerCommented:
Please post your query and the data type of Timestamp field.
karinos57Author Commented:
the query is the same as the one u posted and the timestamp data type is datetime type.  i guess it needs to be converted into var char
dwe761Software EngineerCommented:
No, you should not need to convert to varchar.

Did you replace what I had as [YourTable] with the actual name of your table you are querying?

Did you receive any errors?

Also, Timestamp is actually a reserved word so you may have to put it in square brackets so it knows that is your field name.  Such as :

select * FROM [YourTable]  where [TimeStamp]  >= dateadd(m, -3, getdate())
karinos57Author Commented:
yes, i have changed the table name.  I am not getting any error but query returns an empty table with a header only.
dwe761Software EngineerCommented:
try this.

select top 10  [TimeStamp] ,  [ScriptName] FROM [YourTable] order by [Timestamp] desc

Please change the table name, run it, and post the results.
karinos57Author Commented:
here it is:
TimeStamp      ScriptName
2011-09-12 12:46:50.000      ExpressBuy
2011-09-12 12:46:40.000      SharePoint
2011-09-12 12:41:16.000      ExpressBuy
2011-09-12 12:41:14.000      SharePoint
2011-09-12 12:36:34.000      ExpressBuy
2011-09-12 12:36:28.000      SharePoint
2011-09-12 12:31:39.000      ExpressBuy
2011-09-12 12:31:20.000      SharePoint
2011-09-12 12:26:43.000      ExpressBuy
2011-09-12 12:26:37.000      SharePoint
karinos57Author Commented:
this query returns a single cell like this:
2011-05-12 13:10:11.370
karinos57Author Commented:
i think this has done the trick:
where TimeStamp >=dateadd(month, -3, getdate())

karinos57Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.