Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 time difference

Author  Topic 

PatDeV
Posting Yak Master

197 Posts

Posted - 2006-02-07 : 15:47:41
Hi,

I want to know that how can i get data from last three months to now!! for example data from last three month to todays date (getdate())

Thanks

MichaelP
Jedi Yak

2489 Posts

Posted - 2006-02-07 : 15:56:47
Search the Books Online for DateAdd and DateDiff
You're query should look something like this

SELECT field1, field2
from Mytable
WHERE mydate BETWEEN GetDate() AND DATEADD(mm, -3, GetDate())


Michael

<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-07 : 15:57:58
WHERE SomeDateColumn >= DATEADD(m, -3, GETDATE()) AND SomeDateColumn <= GETDATE()

Tara Kizer
aka tduggan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-02-08 : 03:36:23
More on dates
http://www.sql-server-performance.com/fk_datetime.asp

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -